mysql5.6升級
mysql5.6的升級可以分為以下幾個步驟:
- 安全關閉正在運行的MySQL實例
- 把/usr/local/mysql 的連接由MySQL5.6更改為MySQL5.7
- 啟動MySQL實例,查看是否是MySQL5.7版本
- 使用mysql_upgrade命令升級系統表
首先:停止當前運行的MySQL實例,然后做如下操作
更改之后啟動MySQL實例:
[root@test3 local]# service mysqld start Starting MySQL.. SUCCESS! [root@test3 local]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 31179/sshd tcp 0 0 :::22 :::* LISTEN 31179/sshd tcp 0 0 :::3000 :::* LISTEN 25168/grafana-serve tcp 0 0 :::3306
然后連接MySQL,可以看到MySQL已經有原來的5.6版本升級為5.7版本:
[root@test3 ~]# mysql -S /tmp/mysql.sock -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.22-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]> exit Bye [root@test3 ~]#
這時候利用mysql_upgrade命令升級用戶表
[root@test3 ~]# mysql_upgrade -s -p Enter password: The --upgrade-system-tables option was used, databases won't be touched. Checking if update is needed. Checking server version. Running queries to upgrade MySQL server. Upgrading the sys schema. Upgrade process completed successfully. Checking if update is needed. #需要注意的是這個命令在執行過程中會重構數據庫中所有的表,但是升級的時候,用戶的數據表,是不需要重構的,因此我們使用看-s參數,表示只是重構系統表。
如果這一步的操作沒有報錯,那就說明MySQL實例升級完畢!
mysql的無密碼登錄
第一種:我們可以把用戶名和密碼寫進配置文件中,來實現無密碼登錄。
查看一下mysql默認讀取配置文件的路徑:
[root@test3 mysql]# mysql --help |grep my.cnf order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf [root@test3 mysql]#
我們可以在當前用戶的家目錄下面創建用戶名和密碼,如下:
[root@test2 ~]# cat .my.cnf [client] user=root password=123456 [root@test2 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.6.28-log Source distribution Copyright (c) 2000, 2015, 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>
但是這種方式是明碼保存的很不安全,接下來,我們使用mysql自帶的mysql_condif_editory命令的設置無密碼登錄。

[root@test2 ~]# mysql_config_editor --help mysql_config_editor Ver 1.0 Distrib 5.6.28, for Linux on x86_64 Copyright (c) 2012, 2015, 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. MySQL Configuration Utility. Usage: mysql_config_editor [program options] [command [command options]] -?, --help Display this help and exit. -v, --verbose Write more information. -V, --version Output version information and exit. Variables (--variable-name=value) and boolean options {FALSE|TRUE} Value (after reading options) --------------------------------- ---------------------------------------- verbose FALSE Where command can be any one of the following : set [command options] Sets user name/password/host name/socket/port for a given login path (section). remove [command options] Remove a login path from the login file. print [command options] Print all the options for a specified login path. reset [command options] Deletes the contents of the login file. help Display this usage/help information.
實例:
[root@test2 ~]# mysql_config_editor set --user=root --host=localhost --password Enter password: [root@test2 ~]# ls .mylogin.cnf .mylogin.cnf [root@test2 ~]# #這里的密碼必須在交互輸入,然后就可以直接無密碼登錄 [root@test2 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.6.28-log Source distribution Copyright (c) 2000, 2015, 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>
生成的文件是一個二進制文件,可以使用print參數查看
[root@test2 ~]# mysql_config_editor print --all [client] user = root password = ***** host = localhost [root@test2 ~]#
此命令還可以使用使用--login-path命令,如下:
[root@test2 ~]# mysql_config_editor set --login-path=test --user=root --host=localhost --password Enter password: [root@test2 ~]# mysql_config_editor print --login-path=test [test] user = root password = ***** host = localhost [root@test2 ~]# mysql --login-path=test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 17 Server version: 5.6.28-log Source distribution Copyright (c) 2000, 2015, 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>
--login-path也是在當前家目錄下面生成.mylogin.cnf文件,這個文件以 [ ] 進行標識!