安装yum源
wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
安装mysql
yum install -y mysql mysql-server
启动mysql
systemctl start mysqld
连接mysql
# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
//获取初始密码
# cat /var/log/mysqld.log | grep 'password'
2017-09-20T06:16:07.973662Z 1 [Note] A temporary password is generated for root@localhost: DfqamzHdl7_N //DfqamzHdl7_N就是初始密码
//连接mysql
# mysql -u root -p
Enter password: DfqamzHdl7_N
mysql> //连接成功
设置新密码
mysql>set password = '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
//这是因为初始密码等级设置有点高,可以设低点
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> set password='123456';
Query OK, 0 rows affected (0.00 sec)
//设置成功
允许远程登陆
mysql>use mysql;
Database changed
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
网友评论