安装MySQL(centos7 不支持安装yum mysql5.7 ,所以要自己去下载);

yum -y install wget

wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm

rpm -ivh mysql57-community-release-el7-11.noarch.rpm(直接复制可能找不到,建议手敲);

 

#更新yum软件包

yum check-update 

yum install mysql mysql-server (安装)

systemctl enable mysqld.service(开机自启动mysql)

 

systemctl start mysqld (启动mysql)

---------------------------------------------------

首次在centos7下安装MySQL,客户端连接mysql时报错:

• [root@localhost opt]# /usr/bin/mysql -u root 

• ERROR 1045 (28000): Access denied for user 'root'@'localhost' (usingpassword: NO)

 

找到密码

•[root@localhost opt]#  grep 'temporary password' /var/log/mysqld.log

•2016-07-16T05:01:47.771362Z 1 [Note] Atemporary password is generated for root@localhost: q.)aq!YaH6y-

----------------------------------------------------------------

[root@localhost opt]# /usr/bin/mysql -uroot -p

进入mysql客户端之后,showdatabases; 会提醒先修改密码:

• mysql> show databases; 

• ERROR 1820 (HY000): You must reset your password using ALTER USERstatement before executing this statement.

 

设置密码,以下两种方式均可:

•SET PASSWORD FOR 'root'@'localhost' =PASSWORD('Mysqlpassw0rd.'); 

•   alter user 'root'@'localhost' identified by 'Mysqlpassw0rd.';

-------------------------------------------------------

OK,至此设置成功。注意mysql有密码复杂度的限制。密码太简单会提示:

• mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123'); 

• ERROR 1819 (HY000): Your password does not satisfy the current policyrequirements

--------------------------------------------------------------------

解决办法:

mysql> set global validate_password_policy=0;

set global validate_password_length = 3;

这样,判断密码的标准就基于密码的长度了;

-----------------------------------------------------------

登陆:

/usr/bin/mysql -u root -p

Enter password:

 

#授权远程访问

use mysql;

grant all privileges  on *.* to root@'%' identified by"root";

 

FLUSH RIVILEGES;(可能出错,但已经成功);

MySQL 5.7 默认安装了validate_password 插件。 所以多了以上步骤。

通过my.cnf 配置文件设置密码策略的级别"/etc/my.cnf"

# read_rnd_buffer_size = 2M

datadir=/var/lib/mysql

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

validate_password_policy=2当然你也可以通过 my.cnf 配置文件关闭 validate_password 插件。只需要添加一行

validate_password = off

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐