centOS 7下yum安装MySQL5.7

1、删除centOS7默认安装的mariadb数据库

  yum remove mariadb-libs.x86_64

2、下载Mysql源

  https://dev.mysql.com/downloads/repo/yum/

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

3.安装源

[root@localhost ~]# yum localinstall mysql57-community-release-el7-11.noarch.rpm

[root@localhost ~]# yum search mysql 查看源是否安装

4.安装MySQL

 yum install mysql-community-server

查看mysql是否开;若没又开启用 service mysqld start

[root@localhost get]# netstat -luntp|grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      1505/mysqld
[root@localhost get]# ps -ef|grep mysql
mysql     1505     1  1 21:58 ?        00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root      1537  1258  0 21:58 pts/0    00:00:00 grep --color=auto mysql

[root@localhost get]# lsof -i :3306
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  1505 mysql   22u  IPv6  20035      0t0  TCP *:mysql (LISTEN)
[root@localhost get]#

5.1找出默认密码


[root@localhost ~]# grep "password" /var/log/mysqld.log
2018-12-17T02:58:01.350311Z 1 [Note] A temporary password is generated for root@localhost: 0+bPX(WoFoJk
[root@localhost ~]#

登陆mysql

[root@localhost ~]#mysql -h127.0.0.1-uroot -p //-h后跟的是连接mysql服务器的ip

[root@localhost ~]# mysql  -uroot -p0+bPX\(WoFoJk

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 2

Server version: 5.7.21

5.2 不知道密码的情况下修改密码

1:vim /etc/my.cnf 添加 skip-grant-tables

2:重新启动  service mysqld restart

3:登录

[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24 MySQL Community Server (GPL)

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set authentication_string=password('456789') where user='root';

Query OK, 1 row affected, 1 warning (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;

mysql> eixt;

把/etc/my,cnf 里skip-grant-tables注释掉

service mysqld restart

在mysql系统外,使用mysqladmin
# mysqladmin -u root -p password "test123"
Enter password: 【输入原来的密码】

6、访问出现问题

mysql> show databases;

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

mysql>

如果MySQL数据库用户的密码设置过于简单,数据库在用户登录后会提示重置密码,并且不接受简单的密码。
提示需要重置密码:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
Mysql数据库版本:5.7.1
操作系统:CentOS 7
这个问题是否奇怪,因为明明是刚刚用密码登录了mysql服务器。怎么要重置密码呢?因为密码太简单了,不符合MySQL的安全要求。
参考官方的文档,见http://dev.mysql.com/doc/refman/5.6/en/alter-user.html。重置用户密码操作:
mysql> SET PASSWORD = PASSWORD('123456');   //123456 是重置的新密码
以上操作后又遇到新问题:
ERROR 1819 (HY000): Your password does NOT satisfy the CURRENT policy requirements。
又参考了官方文档,见http://dev.mysql.com/doc/refman/5.7/en/validate-password-plugin.html。
应该是密码过于简单了。 后来用大写字母+数字+特殊字符混合了一个密码。重置密码成功!
以后操作,没有再出现上述问题。
注意:如果只想设置简单密码需要修改两个全局参数:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

查看数据库: 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.00 sec)

7、开启Genelog

 Genelog 记录了所有操作的mysql语句

设置日志存放目录

mysql> set global general_log_file="/tmp/general.log";

Query OK, 0 rows affected (0.00 sec)

开启genelog

mysql> set global general_log=on;

Query OK, 0 rows affected (0.00 sec)
--------------------- 
作者:LIU_BING_ONE 
来源:CSDN 
原文:https://blog.csdn.net/LINU_BW/article/details/85046122 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/LINU_BW/article/details/85052454