1、下載mysql ,同樣,跳過,----需要跟linux版本相對應
2、查看虛擬機內是否有mysql
rpm -qa|grep mysql
如果有,則需要刪除mysql相關文件
* rpm -ev xxx --nodeps
3.使用本地文件在線安裝數據庫:
* 把mysql-community-release-el6-5.noarch.rpm傳到linux根目錄下
* 在根目錄下執行在線安裝指令
yum localinstall mysql-community-release-el6-5.noarch.rpm
4.在線安裝mysql服務
* yum install mysql-server
注意:
1.安裝中斷繼續重新執行指令
2.報錯yum指令正在被其他應用占用:
* ps -ef | grep yum 查看正在使用yum的進程...>進程號
* 根據進程號殺死 kill -9 進程號
5.啟動數據庫服務:
* service mysqld start
* service mysqld status 查看數據庫狀態
設置開機啟動
systemctl enable mysqld
systemctl daemon-reload
6. 設置mysql用戶名密碼:
從日志中獲取初始密碼:
從日志中獲取隨機生成的密碼 [root@node1 db]# grep password /var/log/mysqld.log 2018-07-15T09:01:09.735836Z 1 [Note] A temporary password is generated for root@localhost: ViFg8pWf+,lU [root@node1 db]# mysql -uroot -pViFg8pWf+,lU 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
ALTER USER USER() IDENTIFIED BY '123456';
如果密碼不符合規則,則需要修改策略
第一種、alert
mysql> ALTER USER USER() IDENTIFIED BY 'Reid790!@#$'; Query OK, 0 rows affected (0.00 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Tom579#$%^&'; #針對localhost Query OK, 0 rows affected (0.00 sec) 或者先關閉其密碼策略修改 mysql> select @@validate_password_length; ERROR 1820 (HY000): Unknown error 1820 mysql> ALTER USER USER() IDENTIFIED BY '12345678'; Query OK, 0 rows affected (0.00 sec) validate_password_policy有以下取值: Policy Tests Performed 0 or LOW Length 1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters 2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file 默認是1,即MEDIUM,所以剛開始設置的密碼必須符合長度,且必須含有數字,小寫或大寫字母,特殊字符。
第二種:跳過授權列表skip-grant-tables
[root@node1 db]# mysql ERROR 1045 (28000): Unknown error 1045 [root@node1 db]# vim /etc/my.cnf #使用完后去掉 [mysqld] skip-grant-tables=1 重啟mysql,再修改 [root@node1 db]# systemctl restart mysqld [root@node1 db]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 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> set password = PASSWORD('Reid4909@%&'); ERROR 1290 (HY000): Unknown error 1290 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Tom579#$%^&'; ERROR 1290 (HY000): Unknown error 1290 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> set password = PASSWORD('Reid4909@%&'); ERROR 1133 (42000): mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Tom579#$%^&'; Query OK, 0 rows affected (0.01 sec) mysql> set password for root@localhost = password('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec)
第三種:使用mysql_secure_installation
[root@node1 db]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: Marry583@&%! The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : y New password: Tom579#$%^& Re-enter new password: Tom579#$%^& Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. 為了安全應該yes Remove anonymous users? (Press y|Y for Yes, any other key for No) : No ... skipping. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. 為了安全應該yes Disallow root login remotely? (Press y|Y for Yes, any other key for No) : No ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. 為了安全應該yes Remove test database and access to it? (Press y|Y for Yes, any other key for No) : No ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
第四種:使用update
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('Marry583@&%!'), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost'; Query OK, 1 row affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
7、設置mysql遠程訪問
mysql> create user 'root'@'%' identified with mysql_native_password by 'your password'; Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to 'root'@'%' with grant option; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
8、Navicat連接mysql,輸入ip、用戶名、密碼,點擊連接測試,提示連接成功,就可以正常使用了