zingp

1 安装yum源

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum repolist enabled | grep "mysql.-community."

2 安装mysql

yum -y install mysql-community-server

安装成功后显示:

3 启动和设置开机自启

# 启动和查看启动状态
systemctl start mysqld
systemctl status mysqld

# 开机启动
systemctl enable mysqld
systemctl daemon-reload

4 查看默认root密码

此次安装的是5.7版本,该版本安装成功后,在日志文件/var/log/mysqld.log文件中给root生成了一个默认密码;查看密码:

[@tc_57_161 ~]# grep 'temporary password' /var/log/mysqld.log
2018-03-09T06:15:28.460320Z 1 [Note] A temporary password is generated for root@localhost: ,gjargl63bTr 

可以看到,此次默认root密码是:,gjargl63bTr

5 设置字符编码

vim /etc/my.cnf
# 修改字符编码为utf8 character_set_server = utf8 init_connect = 'SET NAMES utf8'  

重启生效:systemctl restart mysqld

6 登录报错

[@tc_57_161 etc]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[@tc_57_161 etc]# mysql -u root mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)  

解决办法:

在配置文件/etc/my.cnf最后添加一句:skip-grant-tables;

# mysql -u root mysql 
# update mysql.user set authentication_string=password('admin123') where user='root' and Host = 'localhost';
# flush privileges;
# quit;  

用新密码登录试试:

[@tc_57_161 etc]# mysql -u root -padmin123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

成功了!

7 更改root密码

# 改root密码
mysqladmin -uroot -p"旧密码" password "新密码"
mysqladmin -uroot -padmin123 password "123456"

  

  

相关文章: