centos6.4 rpm mysql安装步骤

 

centos6.4 rpm mysql安装步骤

  2737人阅读  评论(1)  收藏  举报

1,检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)  

  

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost ~]# rpm -qa | grep -i mysql  
  2. mysql-libs-5.1.66-2.el6_3.x86_64  
  3. [root@localhost ~]# yum -y remove mysql-libs*  

2,删除掉系统中原有的数据,不然可以导致错误,我实际安装过程中试了几个小时,如果还有错,请参考

点击打开链接

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mv /var/lib/mysql /var/lib/mysql_old  


[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).  
  2. [Note] Plugin 'FEDERATED' is disabled.  
  3. [Note] InnoDB: The InnoDB memory heap is disabled  
  4. [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins  
  5. [Note] InnoDB: Compressed tables use zlib 1.2.3  
  6. [Note] InnoDB: CPU does not support crc32 instructions  
  7. [Note] InnoDB: Using Linux native AIO  
  8. [Note] InnoDB: Initializing buffer pool, size = 128.0M  
  9. [Note] InnoDB: Completed initialization of buffer pool  
  10. [ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different size 640 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages!  
  11. [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!  
  12. [ERROR] Plugin 'InnoDB' init function returned error.  
  13. [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.  
  14. [ERROR] Unknown/unsupported storage engine: InnoDB  
  15. [ERROR] Aborting  
  16.   
  17. [Note] Binlog end  
  18. [Note] Shutting down plugin 'partition'  
  19. [Note] Shutting down plugin 'BLACKHOLE'  
  20. [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'  
  21. [Note] Shutting down plugin 'ARCHIVE'  
  22. [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'  
  23. [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'  
  24. [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'  
  25. [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'  
  26. [Note] Shutting down plugin 'INNODB_SYS_FIELDS'  
  27. [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'  
  28. [Note] Shutting down plugin 'INNODB_SYS_INDEXES'  
  29. [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'  
  30. [Note] Shutting down plugin 'INNODB_SYS_TABLES'  
  31. [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'  
  32. [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'  
  33. [Note] Shutting down plugin 'INNODB_FT_CONFIG'  
  34. [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'  
  35. [Note] Shutting down plugin 'INNODB_FT_DELETED'  
  36. [Note] Shutting down plugin 'INNODB_FT_INSERTED'  
  37. [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'  
  38. [Note] Shutting down plugin 'INNODB_METRICS'  
  39. [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'  
  40. [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'  
  41. [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'  
  42. [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'  
  43. [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'  
  44. [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'  
  45. [Note] Shutting down plugin 'INNODB_CMPMEM'  
  46. [Note] Shutting down plugin 'INNODB_CMP_RESET'  
  47. [Note] Shutting down plugin 'INNODB_CMP'  
  48. [Note] Shutting down plugin 'INNODB_LOCK_WAITS'  
  49. [Note] Shutting down plugin 'INNODB_LOCKS'  
  50. [Note] Shutting down plugin 'INNODB_TRX'  
  51. [Note] Shutting down plugin 'MRG_MYISAM'  
  52. [Note] Shutting down plugin 'MEMORY'  
  53. [Note] Shutting down plugin 'CSV'  
  54. [Note] Shutting down plugin 'MyISAM'  
  55. [Note] Shutting down plugin 'sha256_password'  
  56. [Note] Shutting down plugin 'mysql_old_password'  
  57. [Note] Shutting down plugin 'mysql_native_password'  
  58. [Note] Shutting down plugin 'binlog'  
  59. [Note] /usr/sbin/mysqld: Shutdown complete  
  60.   
  61.  mysqld_safe mysqld from pid file /var/lib/mysql/mysql.pid ended  



2,下载Linux对应的RPM包,如:CentOS6.4_32对应的RPM包,如下:

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. -rwxr--r--. 1 nobody nobody  22838580 Mar 17 17:39 MySQL-client-5.6.17-1.linux_glibc2.5.i386.rpm  
  2. -rwxr--r--. 1 nobody nobody   4135464 Mar 17 17:40 MySQL-devel-5.6.17-1.linux_glibc2.5.i386.rpm  
  3. -rwxr--r--. 1 nobody nobody 109826437 Mar 17 17:40 MySQL-embedded-5.6.17-1.linux_glibc2.5.i386.rpm  
  4. -rwxr--r--. 1 nobody nobody  87469456 Mar 17 17:41 MySQL-server-5.6.17-1.linux_glibc2.5.i386.rpm  
  5. -rwxr--r--. 1 nobody nobody   2362688 Mar 17 17:41 MySQL-shared-5.6.17-1.linux_glibc2.5.i386.rpm  
  6. -rwxr--r--. 1 nobody nobody   5294221 Mar 17 17:41 MySQL-shared-compat-5.6.17-1.linux_glibc2.5.i386.rpm  
  7. -rwxr--r--. 1 nobody nobody  74163863 Mar 17 17:41 MySQL-test-5.6.17-1.linux_glibc2.5.i386.rpm  


3, 安装mysl

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost rpm]# rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm  
  2. [root@localhost rpm]# rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm  
  3. [root@localhost rpm]# rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm  
  4. #修改配置文件位置  
  5. [root@localhost rpm]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf  

4,初使化MYSQL及配置密码

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost rpm]# /usr/bin/mysql_install_db  
  2. [root@localhost rpm]# service mysql start  
  3. [root@localhost rpm]# cat /root/.mysql_secret  #查看root账号密码  
  4. # The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): qKTaFZnl  
  5. [root@localhost ~]# mysql -uroot –pqKTaFZnl  
  6. mysql> SET PASSWORD = PASSWORD('123456');    #设置密码为123456  
  7. mysql> exit  
  8. [root@localhost ~]# mysql -uroot -p123456  

5,允许远程登录

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> use mysql;  
  2. Reading table information for completion of table and column names  
  3. You can turn off this feature to get a quicker startup with -A  
  4.   
  5. Database changed  
  6. mysql> select host,user,password from user;  
  7. +-----------------------+------+-------------------------------------------+  
  8. | host                  | user | password                                  |  
  9. +-----------------------+------+-------------------------------------------+  
  10. | localhost             | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |  
  11. | localhost.localdomain | root | *A4B8196FF869F64E0119B231785E5946EDBA5E26 |  
  12. | 127.0.0.1             | root | *A4B8196FF869F64E0119B231785E5946EDBA5E26 |  
  13. | ::1                   | root | *A4B8196FF869F64E0119B231785E5946EDBA5E26 |  
  14. +-----------------------+------+-------------------------------------------+  
  15. rows in set (0.00 sec)  
  16.   
  17. mysql> update user set password=password('root'where user='root';  
  18. Query OK, 3 rows affected (0.01 sec)  
  19. Rows matched: 4  Changed: 3  Warnings: 0  
  20.   
  21. mysql> update user set host='%' where user='root' and host='localhost';  
  22. Query OK, 1 row affected (0.04 sec)  
  23. Rows matched: 1  Changed: 1  Warnings: 0  
  24.   
  25. mysql> flush privileges;  
  26. Query OK, 0 rows affected (0.00 sec)  

6,设置开机自启动

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost ~]# chkconfig mysql on  
  2. [root@localhost ~]# chkconfig --list | grep mysql  
  3. mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off  

7,查看mysql配置文件位置

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysqld --verbose --help | grep -A 1 'Default options'  

8,MYSQL默认安装位置

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. /var/lib/mysql/               #数据库目录  
  2. /usr/share/mysql              #配置文件目录  
  3. /usr/bin                     #相关命令目录  
  4. /etc/init.d/mysql              #启动脚本  

9,配置字符集

修改字符集和数据存储路径

配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [client]    
  2. password        = 123456    
  3. port            = 3306    
  4. default-character-set=utf8    
  5. [mysqld]    
  6. port            = 3306    
  7. character_set_server=utf8    
  8. character_set_client=utf8    
  9. collation-server=utf8_general_ci    
  10. #(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写)    
  11. lower_case_table_names=1    
  12. #(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; )    
  13. max_connections=1000    
  14. [mysql]    
  15. default-character-set = utf8    



查看字符集

show variables like '%collation%';

show variables like '%char%';

1,检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)  

  

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost ~]# rpm -qa | grep -i mysql  
  2. mysql-libs-5.1.66-2.el6_3.x86_64  
  3. [root@localhost ~]# yum -y remove mysql-libs*  

2,删除掉系统中原有的数据,不然可以导致错误,我实际安装过程中试了几个小时,如果还有错,请参考

点击打开链接

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mv /var/lib/mysql /var/lib/mysql_old  


[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).  
  2. [Note] Plugin 'FEDERATED' is disabled.  
  3. [Note] InnoDB: The InnoDB memory heap is disabled  
  4. [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins  
  5. [Note] InnoDB: Compressed tables use zlib 1.2.3  
  6. [Note] InnoDB: CPU does not support crc32 instructions  
  7. [Note] InnoDB: Using Linux native AIO  
  8. [Note] InnoDB: Initializing buffer pool, size = 128.0M  
  9. [Note] InnoDB: Completed initialization of buffer pool  
  10. [ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different size 640 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages!  
  11. [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!  
  12. [ERROR] Plugin 'InnoDB' init function returned error.  
  13. [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.  
  14. [ERROR] Unknown/unsupported storage engine: InnoDB  
  15. [ERROR] Aborting  
  16.   
  17. [Note] Binlog end  
  18. [Note] Shutting down plugin 'partition'  
  19. [Note] Shutting down plugin 'BLACKHOLE'  
  20. [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'  
  21. [Note] Shutting down plugin 'ARCHIVE'  
  22. [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'  
  23. [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'  
  24. [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'  
  25. [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'  
  26. [Note] Shutting down plugin 'INNODB_SYS_FIELDS'  
  27. [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'  
  28. [Note] Shutting down plugin 'INNODB_SYS_INDEXES'  
  29. [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'  
  30. [Note] Shutting down plugin 'INNODB_SYS_TABLES'  
  31. [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'  
  32. [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'  
  33. [Note] Shutting down plugin 'INNODB_FT_CONFIG'  
  34. [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'  
  35. [Note] Shutting down plugin 'INNODB_FT_DELETED'  
  36. [Note] Shutting down plugin 'INNODB_FT_INSERTED'  
  37. [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'  
  38. [Note] Shutting down plugin 'INNODB_METRICS'  
  39. [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'  
  40. [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'  
  41. [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'  
  42. [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'  
  43. [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'  
  44. [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'  
  45. [Note] Shutting down plugin 'INNODB_CMPMEM'  
  46. [Note] Shutting down plugin 'INNODB_CMP_RESET'  
  47. [Note] Shutting down plugin 'INNODB_CMP'  
  48. [Note] Shutting down plugin 'INNODB_LOCK_WAITS'  
  49. [Note] Shutting down plugin 'INNODB_LOCKS'  
  50. [Note] Shutting down plugin 'INNODB_TRX'  
  51. [Note] Shutting down plugin 'MRG_MYISAM'  
  52. [Note] Shutting down plugin 'MEMORY'  
  53. [Note] Shutting down plugin 'CSV'  
  54. [Note] Shutting down plugin 'MyISAM'  
  55. [Note] Shutting down plugin 'sha256_password'  
  56. [Note] Shutting down plugin 'mysql_old_password'  
  57. [Note] Shutting down plugin 'mysql_native_password'  
  58. [Note] Shutting down plugin 'binlog'  
  59. [Note] /usr/sbin/mysqld: Shutdown complete  
  60.   
  61.  mysqld_safe mysqld from pid file /var/lib/mysql/mysql.pid ended  



2,下载Linux对应的RPM包,如:CentOS6.4_32对应的RPM包,如下:

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. -rwxr--r--. 1 nobody nobody  22838580 Mar 17 17:39 MySQL-client-5.6.17-1.linux_glibc2.5.i386.rpm  
  2. -rwxr--r--. 1 nobody nobody   4135464 Mar 17 17:40 MySQL-devel-5.6.17-1.linux_glibc2.5.i386.rpm  
  3. -rwxr--r--. 1 nobody nobody 109826437 Mar 17 17:40 MySQL-embedded-5.6.17-1.linux_glibc2.5.i386.rpm  
  4. -rwxr--r--. 1 nobody nobody  87469456 Mar 17 17:41 MySQL-server-5.6.17-1.linux_glibc2.5.i386.rpm  
  5. -rwxr--r--. 1 nobody nobody   2362688 Mar 17 17:41 MySQL-shared-5.6.17-1.linux_glibc2.5.i386.rpm  
  6. -rwxr--r--. 1 nobody nobody   5294221 Mar 17 17:41 MySQL-shared-compat-5.6.17-1.linux_glibc2.5.i386.rpm  
  7. -rwxr--r--. 1 nobody nobody  74163863 Mar 17 17:41 MySQL-test-5.6.17-1.linux_glibc2.5.i386.rpm  


3, 安装mysl

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost rpm]# rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm  
  2. [root@localhost rpm]# rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm  
  3. [root@localhost rpm]# rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm  
  4. #修改配置文件位置  
  5. [root@localhost rpm]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf  

4,初使化MYSQL及配置密码

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost rpm]# /usr/bin/mysql_install_db  
  2. [root@localhost rpm]# service mysql start  
  3. [root@localhost rpm]# cat /root/.mysql_secret  #查看root账号密码  
  4. # The random password set for the root user at Wed Dec 11 23:32:50 2013 (local time): qKTaFZnl  
  5. [root@localhost ~]# mysql -uroot –pqKTaFZnl  
  6. mysql> SET PASSWORD = PASSWORD('123456');    #设置密码为123456  
  7. mysql> exit  
  8. [root@localhost ~]# mysql -uroot -p123456  

5,允许远程登录

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> use mysql;  
  2. Reading table information for completion of table and column names  
  3. You can turn off this feature to get a quicker startup with -A  
  4.   
  5. Database changed  
  6. mysql> select host,user,password from user;  
  7. +-----------------------+------+-------------------------------------------+  
  8. | host                  | user | password                                  |  
  9. +-----------------------+------+-------------------------------------------+  
  10. | localhost             | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |  
  11. | localhost.localdomain | root | *A4B8196FF869F64E0119B231785E5946EDBA5E26 |  
  12. | 127.0.0.1             | root | *A4B8196FF869F64E0119B231785E5946EDBA5E26 |  
  13. | ::1                   | root | *A4B8196FF869F64E0119B231785E5946EDBA5E26 |  
  14. +-----------------------+------+-------------------------------------------+  
  15. rows in set (0.00 sec)  
  16.   
  17. mysql> update user set password=password('root'where user='root';  
  18. Query OK, 3 rows affected (0.01 sec)  
  19. Rows matched: 4  Changed: 3  Warnings: 0  
  20.   
  21. mysql> update user set host='%' where user='root' and host='localhost';  
  22. Query OK, 1 row affected (0.04 sec)  
  23. Rows matched: 1  Changed: 1  Warnings: 0  
  24.   
  25. mysql> flush privileges;  
  26. Query OK, 0 rows affected (0.00 sec)  

6,设置开机自启动

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [root@localhost ~]# chkconfig mysql on  
  2. [root@localhost ~]# chkconfig --list | grep mysql  
  3. mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off  

7,查看mysql配置文件位置

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysqld --verbose --help | grep -A 1 'Default options'  

8,MYSQL默认安装位置

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. /var/lib/mysql/               #数据库目录  
  2. /usr/share/mysql              #配置文件目录  
  3. /usr/bin                     #相关命令目录  
  4. /etc/init.d/mysql              #启动脚本  

9,配置字符集

修改字符集和数据存储路径

配置/etc/my.cnf文件,修改数据存放路径、mysql.sock路径以及默认编码utf-8.

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [client]    
  2. password        = 123456    
  3. port            = 3306    
  4. default-character-set=utf8    
  5. [mysqld]    
  6. port            = 3306    
  7. character_set_server=utf8    
  8. character_set_client=utf8    
  9. collation-server=utf8_general_ci    
  10. #(注意linux下mysql安装完后是默认:表名区分大小写,列名不区分大小写; 0:区分大小写,1:不区分大小写)    
  11. lower_case_table_names=1    
  12. #(设置最大连接数,默认为 151,MySQL服务器允许的最大连接数16384; )    
  13. max_connections=1000    
  14. [mysql]    
  15. default-character-set = utf8    



查看字符集

show variables like '%collation%';

show variables like '%char%';

猜你喜欢

转载自blog.csdn.net/dengzhongmingabc/article/details/46333005