CentOS 6.x下的MySQL安装、配置与使用

2017-12-02  本文已影响40人  daking

MySQL简介

MySQL安装

# CentOS6或Red Hat6
wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
# 方式一:通过rpm
rpm -Uvh mysql57-community-release-el6-11.noarch.rpm
# 方式二:通过yum localinstall
yum -y localinstall mysql57-community-release-el6-11.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
# 安装MySQL
yum -y install mysql-community-server
# 是否安装成功
rpm -qa | grep mysql
[mysqld]
explicit_defaults_for_timestamp=true

datadir=/var/lib/mysql/
socket=/var/lib/mysql/mysql.sock
user=mysql 

symbolic-links=0

default-storage-engine=InnoDB 

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# CentOS7及其以上
systemctl start|stop|restart|enable mysqld
# CentOS7以下
service mysqld start|stop|restart|reload
chkconfig mysqld on

MySQL账号

默认root账号

A temporary password is generated for root@localhost: #dol!(gpM7pg
mysql > set password for root@localhost=password('新密码');

创建账号

# 创建账号daking
mysql > create user 'daking'@'%' identified by 'daking';
# 给daking赋予权限
mysql > grant all privileges on *.* to 'daking'@'localhost' identified by 'daking';
mysql > grant all privileges on *.* to 'daking'@'%' identified by 'daking';
# 刷新MySQL权限
mysql > flush privileges;
# 给daking设置密码
mysql > set password for daking@localhost=password('本地登录的密码');
mysql > set password for daking@'%'=password('远程登录的密码');

其他

mysql > select user,host from mysql.user;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| daking    | %         |
| mysql.sys | localhost |
| daking    | localhost |
| root      | localhost |
+-----------+-----------+

MySQL配置

防火墙配置

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

默认存储引擎

mysql > show engines; 

统一utf8字符集

[mysqld]
character_set_server=utf8
collation-server=utf8_general_ci

[client] 
default-character-set=utf8
mysql > show variables like 'character%';
上一篇 下一篇

猜你喜欢

热点阅读