Centos7快速安装Mysql
运行以下命令
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 -y install mysql-community-server;
systemctl start mysqld.service; yum -y remove mysql57-community-release-el7-10.noarch; grep "password" /var/log/mysqld.log;
会生成一个root用户的随机密码
运行命令: mysql -u root -p;
输入红色框内的随机密码
连接上mysql, 进入sql命令行书写模式,设置密码策略, 修改密码安全等级
set global validate_password_policy=0;
set global validate_password_length=3; set global validate_password_mixed_case_count=0; set global validate_password_special_char_count=0; set global validate_password_number_count=0;
将随机密码修改成自己定义的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你想设置的密码';
quit;
设置数据库编码
停止mysql服务:systemctl stop mysqld;
修改数据库配置文件 /etc/my.cnf
赋文件权限:chmod 777 /etc/my.cnf
[mysqld] character-set-server=utf8
max_allowed_packet=20M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [client] default-character-set=utf8 [mysql] default-character-set=utf8
启动mysql服务:systemctl start mysqld;
设置允许远程主机连接
mysql -uroot -p密码; use mysql; update user set host = '%' where user = 'root'; quit; systemctl restart mysqld;
完成!