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.安裝源
[[email protected] ~]# yum localinstall mysql57-community-release-el7-11.noarch.rpm
[[email protected] ~]# yum search mysql 檢視源是否安裝
4.安裝MySQL
yum install mysql-community-server
檢視mysql是否開;若沒又開啟用 service mysqld start
[[email protected] get]# netstat -luntp|grep mysqld
tcp6 0 0 :::3306 :::* LISTEN 1505/mysqld
[
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
[[email protected] get]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 1505 mysql 22u IPv6 20035 0t0 TCP *:mysql (LISTEN)
[[email protected] get]#
5.1找出預設密碼
[[email protected] ~]# grep "password" /var/log/mysqld.log
2018-12-17T02:58:01.350311Z 1 [Note] A temporary password is generated for [email protected]: 0+bPX(WoFoJk
[[email protected] ~]#
登陸mysql
[[email protected] ~]#mysql -h127.0.0.1-uroot -p //-h後跟的是連線mysql伺服器的ip
[[email protected] ~]# 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:登入
[[email protected] ~]# 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
版權宣告:本文為博主原創文章,轉載請附上博文連結!