gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 第一步:Installing MySQL
shell> sudo yum install mysql-community-server第二步:Starting the MySQL Server
shell> sudo service mysqld startshell> sudo service mysqld status 注意:mysql5.7启动后默认会为root@localhost创建密码,所以mysql5.1前的安装完成后本机空密码登录的方式不再适用,所以当使用mysql客户端本机登录时会提示出错,解决办法:
方法1:A superuser account 'root'@'localhost' is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:
官方提示此时可以查看error日志,看到临时密码,使用临时密码登陆后需修改密码
shell> sudo grep 'temporary password' /var/log/mysqld.logshell> mysql -uroot -pmysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 说明:此版本的validate_password插件会默认安装,对密码强度要求比较强,密码必须包含大写字母、小写字母、数字,且长度至少8个字符。
方法2:使用跳过密码检测登录数据库后修改密码,然后重启数据库。
mysql5.7使用rpm包默认安装完后没有生成/etc/my.cnf,但是mysql-community-server安装完成后会生成默认的配置文件default.cnf,需要将此配置文件复制为/etc/my.cnf,然后修改/etc/my.cnf
第一步:
在/etc/my.cnf中添加参数:
skip-grant-table=1
第二步:
启动mysql
shell>/etc/init.d/mysqld start
第三步:
使用mysql客户端连接至mysql服务,执行flush privileges(如果不执行这一步可能会出现无法打开user表的情况),
mysql>user mysql;
mysql>select user,host,password from user;
mysql>grant all on *.* to root@localhost identified by "password";
mysql>flush privileges;
mysql>exit
第三步:
将/etc/my.cnf中添加的skip-gtant-table=1注释掉或者删除,重启mysql服务
shell>/etc/init.d/mysqld stop
shell>/etc/init.d/mysqld start
shell>mysql -uroot -p 'YourPassword'