安装
wget -i -c http: //dev .mysql.com /get/mysql57-community-release-el7-10 .noarch.rpm
|
yum -y install mysql57-community-release-el7-10.noarch.rpm
|
yum list mysql-community-server
|
yum -y install mysql-community-server
|
设置mysql
- 看到上一步中的提示说明Mysql服务已经启动了,不过此时想要连接MySQL,还得找到root用户密码
grep "password" /var/log/mysqld .log
|
或者使用grep 'temporary password' /var/log/mysqld.log查看原始密码
- 修改密码,设置一个符合要求的密码(密码长度至少8位)
ALTER USER 'root' @ 'localhost' IDENTIFIED BY 'new password' ;
|
mysql> ALTER USER 'root' @ 'localhost' IDENTIFIED BY '123' ;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
|
这个其实与validate_password_policy的值有关。
validate_password_policy有以下取值:
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
有时候,只是为了自己测试,不想密码设置得那么复杂,譬如说,我只想设置root的密码为abc@123。
必须修改两个全局参数:
1、修改密码策略
mysql> set global validate_password_policy=0;
|
2、修改密码长度
mysql> set global validate_password_length=1;
|
mysql> ALTER USER 'root' @ 'localhost' IDENTIFIED BY 'abc@123' ;
|
设置mysql的语言utf8
mysql> show variables like '%char%' ;
|
- 使用mysql命令设置:
- 如果仍有编码不是utf8的,请检查配置文件,也可使用mysql命令设置:
set character_set_client = utf8;
set character_set_server = utf8;
set character_set_connection = utf8;
set character_set_database = utf8;
set character_set_results = utf8;
set collation_connection = utf8_general_ci;
set collation_database = utf8_general_ci;
set collation_server = utf8_general_ci;
|
设置mysql的mode
mysql --help| grep 'my.cnf'
|
- 找到my.cnf后,修改my.cnf,在[mysqld]下加入下面这句话。
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
|
设置mysql的远程连接
- 在用Navicat配置远程连接Mysql数据库时遇到如下报错信息,这是由于Mysql配置了不支持远程连接引起的
use mysql;
select host from user where user= 'root' ;
update user set host = '%' where user = 'root' ;
flush privileges;
|
- 如果遇到3306端口无法访问,可以用ufw allow等命令加入入栈规则
firewall-cmd --zone=public --add-port=3306 /tcp --permanent
firewall-cmd --reload
|