MYSQL

转自:http://blog.csdn.net/panda1219/article/details/51897616?locationNum=7&fps=1

===================================================================================================

0. summary

 

    1. 生产环境如何安装MySQL

    .  1.1 innodb_log_file_size说明

    .  1.2 使用编辑的my.cnf安装5.6.31

    .  1.3 安装5.7.13

        .  1.3.1 ssl加密

    2. mysql升级

    .  2.1 停止数据库

    .  2.2 注意datadir参数,改成真实路径,生产环境应该是和软件目录分离的,所以该步骤不需要

    .  2.3 unlink mysql并link5.7路径

    .  2.4 使用mysql_upgrade升级数据文件

    .  2.5 关于降级

 

===================================================================================================

1. 生产环境如何安装mysql

 

参数文件来自

http://www.innomysql.com/article/21730.html

 

#### 需要注意的参数 #####

[html]  view plain  copy
  1. [mysqld]                                ---- [mysqld],[mysqld-5.7]这种tag表明了下面的配置在什么版本下才生效,[mysqld]下均生效  
  2. .....  
  3. .....  
  4. autocommit = 0                         ---- 从5.6版本开始才有的autocommit模式  
  5. datadir = /mdata/mysql_data            ---- 默认在/usr/local/mysql/data下面,权限一定是mysql:mysql  
  6. innodb_undo_logs = 128                 ---- 建议在安装之前就确定好该值,后续修改比较麻烦  
  7. innodb_undo_tablespaces =3             ---- 建议在安装之前就确定好该值,后续修改比较麻烦  
  8. innodb_log_group_home_dir =/redolog/   ---- 根据实际情况修改,权限一定是mysql:mysql  
  9. innodb_undo_directory =/undolog/       ---- 根据实际情况修改,权限一定是mysql:mysql  
  10. innodb_log_file_size = 4G              ---- 该参数在5.5以后才有,安装5.6的时候要注意先把该参数注释掉,等安装完成后,再行打开,后面会演示。5.7无需预先注释  
  11. log_error = error.log                  ---- 指定日志名,默认是$hostname.err  
  12. innodb_buffer_pool_size =2G           ---- 建议配置操作系统内存的70%  

=================================================

1.1 innodb_log_file_size说明 

[html]  view plain  copy
  1. [root@lab11g data]# du -sh* | sort -n  
  2. 1.7M    mysql  
  3. 4.0K    auto.cnf  
  4. 8.0K    test  
  5. 13M     ibdata1  
  6. 16K     lab11g.err  
  7. 49M     ib_logfile0  
  8. 49M     ib_logfile1  
  9. 636K    performance_schema  

初始化是49M, 生产环境推荐用4G, 至少2G. 5.5版本之前innodb有bug, 设大了会影响恢复速度。这个bug在5.5已经修复。

 

=================================================

1.2 使用编辑的my.cnf安装

 

#### 删除之前安装的内容 #### 

[html]  view plain  copy
  1. [root@lab11g mysql]# rm -rfdata/*  
  2. [root@lab11g mysql]# lldata  
  3. 总计 0  
  4. [root@lab11g mysql]# ps -ef| grep mysqld  
  5. root     16596 5918  0 23:15 pts/2    00:00:00 grep mysqld  

#### 编辑配置文件 ####

[html]  view plain  copy
  1. [mysqld]  
  2. ########basicsettings########  
  3. server-id = 11  
  4. port = 3306  
  5. user = mysql  
  6. bind_address =192.168.1.21            ---- 注意改地址  
  7. autocommit = 0  
  8. character_set_server=utf8mb4  
  9. skip_name_resolve1  
  10. max_connections800  
  11. max_connect_errors1000  
  12. #datadir =/data/mysql_data  
  13. datadir =/usr/local/mysql/data                ---- 修改目录  

#### 初始化 ####

[html]  view plain  copy
  1. [root@lab11gmysql]# scripts/mysql_install_db --user=mysql  
  2. Installing MySQLsystem tables...2016-06-25 23:44:16 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' isdeprecated and will be removed in a future release.  
  3. 2016-06-2523:44:16 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in afuture release.  
  4. 2016-06-2523:44:16 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in afuture release.  
  5. 2016-06-2523:44:16 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 17171...  

#### 检查error.err ####

[html]  view plain  copy
  1. 2016-06-2523:44:16 2b1aba700560 InnoDB: innodb-page-size has been changed from thedefault value 16384 to 8192.  
  2. 2016-06-2523:44:16 17171 [Note] InnoDB: Using atomics to ref count buffer pool pages  
  3. 2016-06-2523:44:16 17171 [Note] InnoDB: The InnoDB memory heap is disabled  
  4. 2016-06-2523:44:16 17171 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins  
  5. 2016-06-2523:44:16 17171 [Note] InnoDB: Memory barrier is not used  
  6. 2016-06-2523:44:16 17171 [Note] InnoDB: Compressed tables use zlib 1.2.3  
  7. 2016-06-2523:44:16 17171 [Note] InnoDB: Using Linux native AIO  
  8. 2016-06-2523:44:16 17171 [Note] InnoDB: Using CPU crc32 instructions  
  9. 2016-06-2523:44:16 17171 [Note] InnoDB: Initializing buffer pool, size = 6.0G  
  10. 2016-06-2523:44:18 17171 [Note] InnoDB: Completed initialization of buffer pool  
  11. 2016-06-2523:44:18 17171 [Note] InnoDB: The first specified data file ./ibdata1 did notexist: a new database to be created!  
  12. 2016-06-2523:44:18 17171 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB  
  13. 2016-06-25 23:44:1817171 [Note] InnoDB: Database physically writes the file full: wait...  
  14. 2016-06-2523:44:18 2b1aba700560  InnoDB: Operatingsystem error number 2 in a file operation.  
  15. InnoDB: Theerror means the system cannot find the path specified.  
  16. InnoDB: If youare installing InnoDB, remember that you must create  
  17. InnoDB:directories yourself, InnoDB does not create them.  
  18. 2016-06-25 23:44:18 17171 [ERROR] InnoDB: File/redolog/ib_logfile101: 'create' returned OS error 71.  
  19. 2016-06-25 23:44:18 17171 [ERROR] InnoDB: Cannot create/redolog/ib_logfile101  
  20. 2016-06-2523:44:18 17171 [ERROR] Plugin 'InnoDB' init function returned error.  
  21. 2016-06-2523:44:18 17171 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.  
  22. 2016-06-2523:44:18 17171 [Note] Semi-sync replication initialized for transactions.  
  23. 2016-06-2523:44:18 17171 [Note] Semi-sync replication enabled on the master.  
  24. 2016-06-2523:44:18 17171 [ERROR] Unknown/unsupported storage engine: InnoDB  
  25. 2016-06-2523:44:18 17171 [ERROR] Aborting  
  26.    
  27. 2016-06-2523:44:18 17171 [Note] Binlog end  
  28. 2016-06-2523:44:18 17171 [Note] unregister_replicator OK  
  29. 2016-06-2523:44:18 17171 [Note] ./bin/mysqld: Shutdown complete  

#### 注释掉路径不存在的undo和redo目录,并修改redo大小为1G #### 

[html]  view plain  copy
  1. #innodb_log_group_home_dir= /redolog/  
  2. #innodb_undo_directory= /undolog/  
  3. innodb_log_file_size1G  

#### 重新删除之前的文件并重新初始化 #### 

[html]  view plain  copy
  1. [root@lab11g mysql]# rm -rfdata/*  
  2. [root@lab11gmysql]# scripts/mysql_install_db --user=mysql  
  3. InstallingMySQL system tables...2016-06-25 23:51:40 0 [Warning]'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a futurerelease.  
  4. 2016-06-2523:51:40 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in afuture release.  
  5. 2016-06-2523:51:40 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in afuture release.  
  6. 2016-06-2523:51:40 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 17357...  
  7.    
  8. OK  
  9.    
  10. Filling helptables...2016-06-25 23:52:01 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' isdeprecated and will be removed in a future release.  
  11. 2016-06-2523:52:01 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in afuture release.  
  12. 2016-06-2523:52:01 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in afuture release.  
  13. 2016-06-2523:52:01 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 17392...  
  14. OK  
  15.    
  16. To start mysqldat boot time you have to copy  
  17. support-files/mysql.serverto the right place for your system  
  18.    
  19. PLEASE REMEMBERTO SET A PASSWORD FOR THE MySQL root USER !  
  20. To do so, startthe server, then issue the following commands:  
  21.    
  22.   ./bin/mysqladmin -u root password'new-password'  
  23.   ./bin/mysqladmin -u root -h lab11g password'new-password'  
  24.    
  25. Alternativelyyou can run:  
  26.    
  27.   ./bin/mysql_secure_installation  
  28.    
  29. which will alsogive you the option of removing the test  
  30. databases andanonymous user created by default.  Thisis  
  31. stronglyrecommended for production servers.  
  32.    
  33. See the manualfor more instructions.  
  34.    
  35. You can startthe MySQL daemon with:  
  36.    
  37.   cd . ; ./bin/mysqld_safe &  
  38.    
  39. You can testthe MySQL daemon with mysql-test-run.pl  
  40.    
  41.   cd mysql-test ; perl mysql-test-run.pl  
  42.    
  43. Please reportany problems at http://bugs.mysql.com/  
  44.    
  45. The latestinformation about MySQL is available on the web at  
  46.    
  47.   http://www.mysql.com  
  48.    
  49. Support MySQLby buying support/licenses at http://shop.mysql.com  
  50.    
  51. WARNING: Foundexisting config file ./my.cnf on the system.  
  52. Because thisfile might be in use, it was not replaced,  
  53. but was used inbootstrap (unless you used --defaults-file)  
  54. and when youlater start the server.  
  55. The new defaultconfig file was created as ./my-new.cnf,  
  56. please compareit with your file and take the changes you need.  
  57.    
  58. WARNING:Default config file /etc/my.cnf exists on the system  
  59. This file willbe read by default by the MySQL server  
  60. If you do notwant to use this, either remove it, or use the  
  61. --defaults-fileargument to mysqld_safe when starting the server  
  62.    
  63. [root@lab11gmysql]# ll data  
  64. 总计 2134304  
  65. -rw-rw---- 1mysql mysql      63378 06-25 23:51bin.000001  
  66. -rw-rw---- 1mysql mysql    1178981 06-25 23:52bin.000002  
  67. -rw-rw---- 1mysql mysql         26 06-25 23:52bin.index  
  68. -rw-rw---- 1mysql mysql       7189 06-25 23:52error.log  
  69. -rw-rw---- 1mysql mysql        865 06-25 23:52ib_buffer_pool  
  70. -rw-rw---- 1mysql mysql   12582912 06-25 23:52ibdata1  
  71. -rw-rw---- 1mysql mysql 1073741824 06-25 23:52 ib_logfile0  
  72. -rw-rw---- 1mysql mysql 1073741824 06-25 23:51 ib_logfile1  
  73. drwx------ 2mysql mysql       4096 06-25 23:51 mysql  
  74. drwx------ 2mysql mysql       4096 06-25 23:51performance_schema  
  75. drwx------ 2mysql mysql       4096 06-25 23:51 test  
  76. -rw-rw---- 1mysql mysql    7340032 06-25 23:52undo001  
  77. -rw-rw---- 1mysql mysql    7340032 06-25 23:52undo002  
  78. -rw-rw---- 1mysql mysql    7340032 06-25 23:52undo003  
  79. [root@lab11gmysql]# /etc/init.d/mysql.server start  
  80. StartingMySQL....[确定]  

安装完成,尝试登陆报错,如下: 

[html]  view plain  copy
  1. [root@lab11gmysql]# bin/mysql  
  2. ERROR 1045(28000): Access denied for user 'root'@'localhost' (using password: NO)  
  3. [root@lab11gmysql]# bin/mysql -u root -p  
  4. Enter password:  
  5. ERROR 1045(28000): Access denied for user 'root'@'localhost' (using password: YES)  

#### 注释掉autocommit参数 #### 

[html]  view plain  copy
  1. #autocommit = 0  

#### 删除创建内容再次初始化 ####

[html]  view plain  copy
  1. [root@lab11gmysql]# scripts/mysql_install_db --user=mysql  
  2. InstallingMySQL system tables...2016-06-26 00:11:31 0 [Warning]'ERROR_FOR_DIVISION_BY_ZERO' is deprecated and will be removed in a futurerelease.  
  3. 2016-06-2600:11:31 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in a futurerelease.  
  4. 2016-06-2600:11:31 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in afuture release.  
  5. 2016-06-2600:11:31 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 18864...  
  6. OK  
  7.    
  8. Filling helptables...2016-06-26 00:11:50 0 [Warning] 'ERROR_FOR_DIVISION_BY_ZERO' isdeprecated and will be removed in a future release.  
  9. 2016-06-2600:11:50 0 [Warning] 'NO_ZERO_DATE' is deprecated and will be removed in afuture release.  
  10. 2016-06-2600:11:50 0 [Warning] 'NO_ZERO_IN_DATE' is deprecated and will be removed in afuture release.  
  11. 2016-06-2600:11:50 0 [Note] ./bin/mysqld (mysqld 5.6.31-log) starting as process 18892...  
  12. OK  
  13.    
  14. To start mysqldat boot time you have to copy  
  15. support-files/mysql.serverto the right place for your system  
  16.    
  17. PLEASE REMEMBERTO SET A PASSWORD FOR THE MySQL root USER !  
  18. To do so, startthe server, then issue the following commands:  
  19.    
  20.   ./bin/mysqladmin -u root password'new-password'  
  21.   ./bin/mysqladmin -u root -h lab11g password'new-password'  
  22.    
  23. Alternativelyyou can run:  
  24.    
  25.   ./bin/mysql_secure_installation  
  26.    
  27. which will alsogive you the option of removing the test  
  28. databases andanonymous user created by default.  Thisis  
  29. stronglyrecommended for production servers.  
  30.    
  31. See the manualfor more instructions.  
  32.    
  33. You can startthe MySQL daemon with:  
  34.    
  35.   cd . ; ./bin/mysqld_safe &  
  36.    
  37. You can testthe MySQL daemon with mysql-test-run.pl  
  38.    
  39.   cd mysql-test ; perl mysql-test-run.pl  
  40.    
  41. Please reportany problems at http://bugs.mysql.com/  
  42.    
  43. The latestinformation about MySQL is available on the web at  
  44.    
  45.   http://www.mysql.com  
  46.    
  47. Support MySQLby buying support/licenses at http://shop.mysql.com  
  48.    
  49. WARNING: Foundexisting config file ./my.cnf on the system.  
  50. Because thisfile might be in use, it was not replaced,  
  51. but was used inbootstrap (unless you used --defaults-file)  
  52. and when youlater start the server.  
  53. The new defaultconfig file was created as ./my-new.cnf,  
  54. please compareit with your file and take the changes you need.  
  55.    
  56. WARNING:Default config file /etc/my.cnf exists on the system  
  57. This file willbe read by default by the MySQL server  
  58. If you do notwant to use this, either remove it, or use the  
  59. --defaults-fileargument to mysqld_safe when starting the server  
  60.    
  61.    
  62. [root@lab11gmysql]# /etc/init.d/mysql.server start  
  63. StartingMySQL...[确定]  
  64. [root@lab11gmysql]# mysql  
  65. Welcome to theMySQL monitor.  Commands end with ; or\g.  
  66. Your MySQLconnection id is 1  
  67. Server version:5.6.31-log MySQL Community Server (GPL)  
  68.    
  69. Copyright (c)2000, 2016, Oracle and/or its affiliates. All rights reserved.  
  70.    
  71. Oracle is aregistered trademark of Oracle Corporation and/or its  
  72. affiliates.Other names may be trademarks of their respective  
  73. owners.  
  74.    
  75. Type 'help;' or'\h' for help. Type '\c' to clear the current input statement.  
  76.    
  77. mysql>  

#### 还原autocommit参数并重新启动 ####

[html]  view plain  copy
  1. [root@lab11gmysql]# mysqladmin shutdown  
  2. [root@lab11gmysql]# /etc/init.d/mysql.server start  
  3. StartingMySQL...[确定]  
  4. [root@lab11gmysql]# mysql  
  5. Welcome to theMySQL monitor.  Commands end with ; or\g.  
  6. Your MySQLconnection id is 1  
  7. Server version:5.6.31-log MySQL Community Server (GPL)  
  8.    
  9. Copyright (c)2000, 2016, Oracle and/or its affiliates. All rights reserved.  
  10.    
  11. Oracle is aregistered trademark of Oracle Corporation and/or its  
  12. affiliates.Other names may be trademarks of their respective  
  13. owners.  
  14.    
  15. Type 'help;' or'\h' for help. Type '\c' to clear the current input statement.  
  16.    
  17. mysql>  

*************************************************

1.3 安装5.7.13

 

5.7.13的解压包里没有包含INSTALL_BINARY, 可以拿MySQL-5.7.9为例,如下:

[html]  view plain  copy
  1. shell> yum searchlibaio  # search for info  
  2. shell> yum installlibaio # install library  
  3. shell> groupadd mysql  
  4. shell> useradd -r -gmysql mysql  
  5. shell> cd /usr/local  
  6. shell> tar zxvf/path/to/mysql-VERSION-OS.tar.gz  
  7. shell> ln -sfull-path-to-mysql-VERSION-OS mysql  
  8. shell> cd mysql  
  9. shell> mkdir mysql-files  
  10. shell> chmod 770mysql-files  
  11. shell> chown -R mysql .  
  12. shell> chgrp -R mysql .  
  13. shell>bin/mysql_install_db --user=mysql    #Before MySQL 5.7.6  
  14. shell> bin/mysqld--initialize --user=mysql # MySQL 5.7.6 and up  
  15. shell>bin/mysql_ssl_rsa_setup              #MySQL 5.7.6 and up              ---- 可选,希望你产生一个ssl的密钥  
  16. shell> chown -R root .  
  17. shell> chown -R mysqldata mysql-files  
  18. shell> bin/mysqld_safe--user=mysql &  
  19. # Next command is optional  
  20. shell> cpsupport-files/mysql.server /etc/init.d/mysql.server  

#### 前面步骤省略,安装过程如下 ####

[html]  view plain  copy
  1. [root@lab11g local]# pwd  
  2. /usr/local  
  3. [root@lab11g local]# ln -smysql-5.7.13-linux-glibc2.5-x86_64 mysql  
  4. [root@lab11g local]# cdmysql  
  5. [root@lab11g mysql]# mkdirmysql-files  
  6. [root@lab11g mysql]# chmod770 mysql-files  
  7. [root@lab11g mysql]# chown-R mysql .  
  8. [root@lab11g mysql]# chgrp-R mysql .  
  9. [root@lab11g mysql]#bin/mysqld --initialize --user=mysql  
  10. [root@lab11g mysql]#bin/mysql_ssl_rsa_setup  
  11. Generating a 2048 bit RSAprivate key  
  12. ............................................................................+++  
  13. ..+++  
  14. writing new private key to'ca-key.pem'  
  15. -----  
  16. Generating a 2048 bit RSAprivate key  
  17. ...........................+++  
  18. .........................................+++  
  19. writing new private key to'server-key.pem'  
  20. -----  
  21. Generating a 2048 bit RSAprivate key  
  22. ................................................................................+++  
  23. ..............+++  
  24. writing new private key to'client-key.pem'  
  25. -----  
  26. [root@lab11g mysql]# chown-R root .  
  27. [root@lab11g mysql]# chown-R mysql data mysql-files  
  28. [root@lab11g mysql]#bin/mysqld_safe --user=mysql &  
  29. [1] 8239  
  30. [root@lab11g mysql]#2016-07-06T01:50:19.169410Z mysqld_safe Logging to '/usr/local/mysql/data/error.log'.  
  31. 2016-07-06T01:50:19.195888Zmysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data  
  32.    
  33. [root@lab11g mysql]# cpsupport-files/mysql.server /etc/init.d/mysql.server  

5.7安装过程中会产生临时密码,登录时需要,error.log显示如下: 

[html]  view plain  copy
  1. 2016-07-06T09:47:33.258113+08:001 [Note] A temporary password is generated for root@localhost: PqPf-whqT7gi  

#### 使用临时密码尝试登录 ####

[html]  view plain  copy
  1. [root@lab11g mysql]# mysql-p"PqPf-whqT7gi"  
  2. mysql: [Warning] Using apassword on the command line interface can be insecure.  
  3. Welcome to the MySQLmonitor.  Commands end with ; or \g.  
  4. Your MySQL connection id is4  
  5. Server version: 5.7.13-log  
  6.    
  7. Copyright (c) 2000, 2016,Oracle and/or its affiliates. All rights reserved.  
  8.    
  9. Oracle is a registeredtrademark of Oracle Corporation and/or its  
  10. affiliates. Other names maybe trademarks of their respective  
  11. owners.  
  12.    
  13. Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.  
  14.    
  15. mysql> use sys  
  16. ERROR 1820 (HY000): Youmust reset your password using ALTER USER statement before executing thisstatement. ---- 提示更改密码  
  17. mysql> set password ='123';                                                           ----5.6是set password =password('123');  
  18. Query OK, 0 rows affected(5.02 sec)  
  19.    
  20. mysql> set password ='mysql';  
  21. Query OK, 0 rows affected(0.01 sec)  
  22.    
  23. mysql> use sys  
  24. Reading table informationfor completion of table and column names  
  25. You can turn off thisfeature to get a quicker startup with -A  
  26.    
  27. Database changed  

*************************************************

1.3.1 ssl加密 

[html]  view plain  copy
  1. mysql> status  
  2. --------------  
  3. mysql  Ver 14.14 Distrib 5.7.13, for linux-glibc2.5(x86_64) using  EditLine wrapper  
  4.    
  5. Connection id:         2  
  6. Current database:       
  7. Current user:          root@localhost  
  8. SSL:                    Not in use                      ----这种方式是不会使用ssl方式  
  9. Current pager:         stdout  
  10. Using outfile:         ''  
  11. Using delimiter:       ;  
  12. Server version:        5.7.13-log  
  13. Protocol version:      10  
  14. Connection:            Localhost via UNIX socket      ---- 本地登录  
  15. Server characterset:   utf8mb4  
  16. Db     characterset:    utf8mb4  
  17. Client characterset:   gb2312  
  18. Conn.  characterset:   gb2312  
  19. UNIX socket:           /tmp/mysql.sock  
  20. Uptime:                 1 min 35 sec  

需要使用TCP连接方式才会使用,如下: 

[html]  view plain  copy
  1. [root@lab11g mysql]# mysql-h 127.0.0.1 -u root -p  
  2. Enter password:  
  3. ERROR 2003 (HY000): Can'tconnect to MySQL server on '127.0.0.1' (111)  
  4. [root@lab11g data]# netstat-ntl  
  5. Active Internet connections(only servers)  
  6. Proto Recv-Q Send-Q LocalAddress               ForeignAddress             State       
  7. tcp        0     0 127.0.0.1:2208             0.0.0.0:*                   LISTEN       
  8. tcp        0     0 192.168.1.21:3306          0.0.0.0:*                  LISTEN       
  9. tcp        0     0 0.0.0.0:111                0.0.0.0:*                   LISTEN       
  10. tcp        0     0 0.0.0.0:722                0.0.0.0:*                   LISTEN       
  11. tcp        0     0 0.0.0.0:21                 0.0.0.0:*                  LISTEN       
  12. tcp        0     0 0.0.0.0:22                 0.0.0.0:*                   LISTEN       
  13. tcp        0     0 127.0.0.1:631              0.0.0.0:*                   LISTEN       
  14. tcp        0     0 127.0.0.1:2207              0.0.0.0:*                   LISTEN   

实际上是因为my.cnf中设置了bind_address. 注释掉bind_address

[html]  view plain  copy
  1. #bind_address =192.168.1.21  
  2.    
  3. [root@lab11g mysql]# mysql-h 127.0.0.1 -u root -p  
  4. Enter password:  
  5. ERROR 1130 (HY000): Host'127.0.0.1' is not allowed to connect to this MySQL server  

上面报错是因为没有这个用户,后面会说。建立用户并登录,如下: 

[html]  view plain  copy
  1. mysql> create user'root'@'127.0.0.1' identified by 'mysql';  
  2. Query OK, 0 rows affected(5.01 sec)  
  3.    
  4. mysql> exit  
  5. Bye  
  6. [root@lab11g mysql]# mysql-h 127.0.0.1 -u root -p  
  7. Enter password:  
  8. ......  
  9.    
  10. mysql> status  
  11. --------------  
  12. mysql  Ver 14.14 Distrib 5.7.13, for linux-glibc2.5(x86_64) using  EditLine wrapper  
  13.    
  14. Connection id:         6  
  15. Current database:       
  16. Current user:          root@127.0.0.1  
  17. SSL:                    Cipher in use is DHE-RSA-AES256-SHA                           ---- 使用了ssl加密  
  18. Current pager:         stdout  
  19. Using outfile:         ''  
  20. Using delimiter:       ;  
  21. Server version:        5.7.13-log MySQL Community Server (GPL)  
  22. Protocol version:      10  
  23. Connection:            127.0.0.1 via TCP/IP                                           ----TCP连接方式  
  24. Server characterset:   utf8mb4  
  25. Db     characterset:    utf8mb4  
  26. Client characterset:   gb2312  
  27. Conn.  characterset:   gb2312  
  28. TCP port:               3306  
  29. Uptime:                 2 hours 16 min 12 sec  
  30.    
  31. Threads: 1  Questions: 49 Slow queries: 0  Opens: 146  Flush tables: 1  Open tables: 139  Queries per second avg: 0.005  
  32. --------------  

更多可参考:

http://www.innomysql.com/article/24297.html

 

===================================================================================================

2. MySQL升级

 

这里演示从5.6升级到5.7

 

*************************************************

2.1 停止数据库 

[html]  view plain  copy
  1. [root@lab11g mysql]#/etc/init.d/mysql.server stop  
  2. Shutting down MySQL..[确定]  

*************************************************

2.2 注意datadir参数,改成真实路径,生产环境应该是和软件目录分离的,所以该步骤不需要 

[html]  view plain  copy
  1. datadir = /usr/local/mysql-5.6.31-linux-glibc2.5-x86_64/data  

*************************************************

2.3 unlink mysql并link5.7路径 

[html]  view plain  copy
  1. [root@lab11g local]# unlinkmysql  
  2. [root@lab11g local]# ln -smysql-5.7.13-linux-glibc2.5-x86_64 mysql  
  3. [root@lab11g local]#/etc/init.d/mysql.server start  
  4. StartingMySQL.............                                [确定]  
  5. [root@lab11g local]# mysql  
  6. Welcome to the MySQLmonitor.  Commands end with ; or \g.  
  7. Your MySQL connection id is2  
  8. Server version: 5.7.13-logMySQL Community Server (GPL)  
  9.    
  10. Copyright (c) 2000, 2016,Oracle and/or its affiliates. All rights reserved.  
  11.    
  12. Oracle is a registeredtrademark of Oracle Corporation and/or its  
  13. affiliates. Other names maybe trademarks of their respective  
  14. owners.  
  15.    
  16. Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.  
  17.    
  18. mysql> show databases;  
  19. +--------------------+  
  20. | Database           |  
  21. +--------------------+  
  22. | information_schema |  
  23. | mysql              |  
  24. | performance_schema |  
  25. | test               |  
  26. +--------------------+  
  27. 4 rows in set (0.00 sec)  
  28.    
  29. mysql> use test  
  30. Database changed  
  31. mysql> show tables;  
  32. Empty set (0.00 sec)  

这时候启动发现已经是5.7了,说明5.6和5.7的二进制文件是兼容的,但是error.log里面有很多Warning甚至ERROR, 如下: 

[html]  view plain  copy
  1. 2016-07-06T20:35:39.334153+08:000 [ERROR] Incorrect definition of tableperformance_schema.events_waits_current: expected column 'NESTING_EVENT_TYPE'at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT',found type enum('STATEMENT','STAGE','WAIT').  
  2. 2016-07-06T20:35:39.334202+08:000 [ERROR] Incorrect definition of tableperformance_schema.events_waits_history: expected column 'NESTING_EVENT_TYPE'at position 15 to have type enum('TRANSACTION','STATEMENT','STAGE','WAIT',found type enum('STATEMENT','STAGE','WAIT').  

*************************************************

2.4 使用mysql_upgrade升级数据文件 

[html]  view plain  copy
  1. [root@lab11g data]#mysql_upgrade                                  ----如果有密码的话也要mysql_upgrade  
  2. Checking if update isneeded.  
  3. Checking server version.  
  4. Running queries to upgradeMySQL server.  
  5. Checking system database.  
  6. mysql.columns_priv                                 OK  
  7. mysql.db                                           OK  
  8. mysql.engine_cost                                  OK  
  9. mysql.event                                        OK  
  10. mysql.func                                         OK  
  11. mysql.general_log                                  OK  
  12. mysql.gtid_executed                                OK  
  13. mysql.help_category                                OK  
  14. mysql.help_keyword                                 OK  
  15. mysql.help_relation                                OK  
  16. mysql.help_topic                                   OK  
  17. mysql.innodb_index_stats                           OK  
  18. mysql.innodb_table_stats                           OK  
  19. mysql.ndb_binlog_index                             OK  
  20. mysql.plugin                                       OK  
  21. mysql.proc                                         OK  
  22. mysql.procs_priv                                   OK  
  23. mysql.proxies_priv                                 OK  
  24. mysql.server_cost                                  OK  
  25. mysql.servers                                      OK  
  26. mysql.slave_master_info                            OK  
  27. mysql.slave_relay_log_info                         OK  
  28. mysql.slave_worker_info                            OK  
  29. mysql.slow_log                                     OK  
  30. mysql.tables_priv                                  OK  
  31. mysql.time_zone                                    OK  
  32. mysql.time_zone_leap_second                        OK  
  33. mysql.time_zone_name                               OK  
  34. mysql.time_zone_transition                         OK  
  35. mysql.time_zone_transition_type                    OK  
  36. mysql.user                                         OK  
  37. Upgrading the sys schema.  
  38. Checking databases.  
  39. sys.sys_config                                     OK  
  40. Upgrade process completedsuccessfully.  
  41. Checking if update isneeded.  
  42. [root@lab11g data]# mysql  
  43. Welcome to the MySQLmonitor.  Commands end with ; or \g.  
  44. Your MySQL connection id is4  
  45. Server version: 5.7.13-logMySQL Community Server (GPL)  
  46.    
  47. Copyright (c) 2000, 2016,Oracle and/or its affiliates. All rights reserved.  
  48.    
  49. Oracle is a registeredtrademark of Oracle Corporation and/or its  
  50. affiliates. Other names maybe trademarks of their respective  
  51. owners.  
  52.    
  53. Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.  
  54.    
  55. mysql> show databases;  
  56. +--------------------+  
  57. | Database           |  
  58. +--------------------+  
  59. | information_schema |  
  60. | mysql              |  
  61. | performance_schema |  
  62. | sys                |                                 ---- 5.7的sys库  
  63. | test               |                                 ---- 5.6的test库  
  64. +--------------------+  
  65. 5 rows in set (0.00 sec)  

mysql_upgrade会把所有的包括业务表全部重新建一遍,但是只要是innodb都是兼容的,如果数据量很大,是没有必要的。只升级系统表即可,如下: 

[html]  view plain  copy
  1. [root@lab11g data]#mysql_upgrade --help  
  2. ......  
  3.   -s, --upgrade-system-tables  
  4.                       Only upgrade the systemtables, do not try to upgrade the  
  5.                       data.  
  6. ......  
  7. [root@lab11g data]#mysql_upgrade -s --force                                           ----我这里已经升级过了,所以force  
  8. The --upgrade-system-tablesoption was used, databases won't be touched.  
  9. Checking server version.  
  10. Running queries to upgradeMySQL server.  
  11. The sys schema is alreadyup to date (version 1.5.0).  
  12. Upgrade process completedsuccessfully.  
  13. Checking if update isneeded.  

什么时候不需要-s? 比如老版本的业务表没有按照新特性来存,升级会有一些性能的提升。但是提升不会太大,所以说通常来说没有必要。

一般来说非跨版本升级,有可能有参数过期,日志里面会有Warning, 如下: 

[html]  view plain  copy
  1. 2016-07-06T21:01:54.109662+08:000 [Warning] InnoDB: Using innodb_file_format is deprecated and the parametermay be removed in future releases. See http://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html  
  2. 2016-07-06T21:01:54.109692+08:000 [Warning] InnoDB: Using innodb_file_format_max is deprecated and theparameter may be removed in future releases. Seehttp://dev.mysql.com/doc/refman/5.7/en/innodb-file-format.html  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值