安装
- 安装依赖
# 下载
shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# 安装 mysql 源
shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm
- 用下面的命令检查 mysql 源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*"
- 启动 mysql
yum install -y mysql-community-server
配置
- 启动 mysql。 关闭命令是(
systemctl start|stop
)
systemctl start mysqld
- 查看mysql 状态
systemctl status mysqld
- 设置开机自启动
systemctl enable mysqld
# 重载所有修改过的配置文件
systemctl daemon-reload
- 生成密码
grep 'password' /var/log/mysqld.log
-
设置密码
- 登录 mysql
mysql -uroot -p
- 设置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'ABCdef123!';
- 登录 mysql
-
添加一个允许远程连接的帐户
GRANT ALL PRIVILEGES ON *.* TO 'GanYuHui'@'%' IDENTIFIED BY 'ABCdef123!' WITH GRANT OPTION;
- 允许 root 远程链接
use mysql;
UPDATE user SET Host='%' WHERE User='root';
flush privileges;
- 设置默认编码为 utf8
vim /etc/my.cnf
# 新增配置
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
- 重启 mysql 服务
systemctl restart mysqld