• 售前

  • 售后

热门帖子
入门百科

centos 6.9安装mysql的详细教程

[复制链接]
飞一航符cx 显示全部楼层 发表于 2021-10-25 20:16:01 |阅读模式 打印 上一主题 下一主题
1、确认mysql是否已安装,有下面的代码可知
  1. [root@cdh1 zjl]# yum list installed mysql*
  2. Loaded plugins: fastestmirror, refresh-packagekit, security
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.zju.edu.cn
  5. * extras: mirrors.aliyun.com
  6. * updates: mirrors.aliyun.com
  7. Installed Packages
  8. MySQL-python.x86_64 1.2.3-0.3.c1.1.el6 @base      
  9. mysql-libs.x86_64 5.1.73-8.el6_8  @anaconda-CentOS-201703281317.x86_64/6.9
复制代码
2、卸载已安装的mysql,发起利用yum命令,因为yum命令可以自动删除与mysql干系的依赖;如果利用rpm命令,则还必要手动去删除和mysql干系的文件,比较贫困
  1. [root@cdh1 zjl]# yum remove MySQL-python.x86_64 mysql-libs.x86_64
  2. Loaded plugins: fastestmirror, refresh-packagekit, security
  3. Setting up Remove Process
  4. Resolving Dependencies
  5. --> Running transaction check
  6. ---> Package MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 will be erased
  7. --> Processing Dependency: MySQL-python for package: cloudera-manager-agent-5.11.1-1.cm5111.p0.9.el6.x86_64
  8. ---> Package mysql-libs.x86_64 0:5.1.73-8.el6_8 will be erased
  9. --> Processing Dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-8.el6.x86_64
  10. --> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-8.el6.x86_64
  11. --> Processing Dependency: mysql-libs for package: 2:postfix-2.6.6-8.el6.x86_64
  12. --> Running transaction check
  13. ---> Package cloudera-manager-agent.x86_64 0:5.11.1-1.cm5111.p0.9.el6 will be erased
  14. ---> Package postfix.x86_64 2:2.6.6-8.el6 will be erased
  15. --> Processing Dependency: /usr/sbin/sendmail for package: redhat-lsb-core-4.0-7.el6.centos.x86_64
  16. --> Processing Dependency: /usr/sbin/sendmail for package: cronie-1.4.4-16.el6_8.2.x86_64
  17. --> Running transaction check
  18. ---> Package cronie.x86_64 0:1.4.4-16.el6_8.2 will be erased
  19. --> Processing Dependency: cronie = 1.4.4-16.el6_8.2 for package: cronie-anacron-1.4.4-16.el6_8.2.x86_64
  20. ---> Package redhat-lsb-core.x86_64 0:4.0-7.el6.centos will be erased
  21. --> Processing Dependency: redhat-lsb-core(x86-64) = 4.0 for package: redhat-lsb-printing-4.0-7.el6.centos.x86_64
  22. --> Processing Dependency: redhat-lsb-core(x86-64) = 4.0-7.el6.centos for package: redhat-lsb-4.0-7.el6.centos.x86_64
  23. --> Processing Dependency: redhat-lsb-core(x86-64) = 4.0 for package: redhat-lsb-graphics-4.0-7.el6.centos.x86_64
  24. --> Running transaction check
  25. ---> Package cronie-anacron.x86_64 0:1.4.4-16.el6_8.2 will be erased
  26. ---> Package redhat-lsb.x86_64 0:4.0-7.el6.centos will be erased
  27. --> Processing Dependency: redhat-lsb(x86-64) = 4.0-7.el6.centos for package: redhat-lsb-compat-4.0-7.el6.centos.x86_64
  28. ---> Package redhat-lsb-graphics.x86_64 0:4.0-7.el6.centos will be erased
  29. ---> Package redhat-lsb-printing.x86_64 0:4.0-7.el6.centos will be erased
  30. --> Running transaction check
  31. ---> Package redhat-lsb-compat.x86_64 0:4.0-7.el6.centos will be erased
  32. --> Processing Dependency: /etc/cron.d for package: crontabs-1.10-33.el6.noarch
  33. --> Processing Dependency: /etc/cron.d for package: sysstat-9.0.4-33.el6.x86_64
  34. --> Restarting Dependency Resolution with new changes.
  35. --> Running transaction check
  36. ---> Package crontabs.noarch 0:1.10-33.el6 will be erased
  37. ---> Package sysstat.x86_64 0:9.0.4-33.el6 will be erased
  38. --> Finished Dependency Resolution
  39. Dependencies Resolved
  40. ====================================================================
  41. Package    Arch Version     Repository
  42.                 Size
  43. ====================================================================
  44. Removing:
  45. MySQL-python   x86_64 1.2.3-0.3.c1.1.el6  @base 246 k
  46. mysql-libs    x86_64 5.1.73-8.el6_8   @anaconda-CentOS-201703281317.x86_64/6.9
  47.                 4.0 M
  48. Removing for dependencies:
  49. cloudera-manager-agent x86_64 5.11.1-1.cm5111.p0.9.el6 @/cloudera-manager-agent-5.11.1-1.cm5111.p0.9.el6.x86_64
  50.                 71 M
  51. cronie     x86_64 1.4.4-16.el6_8.2   @anaconda-CentOS-201703281317.x86_64/6.9
  52.                 174 k
  53. cronie-anacron   x86_64 1.4.4-16.el6_8.2   @anaconda-CentOS-201703281317.x86_64/6.9
  54.                 43 k
  55. crontabs    noarch 1.10-33.el6    @anaconda-CentOS-201703281317.x86_64/6.9
  56.                 2.4 k
  57. postfix    x86_64 2:2.6.6-8.el6   @anaconda-CentOS-201703281317.x86_64/6.9
  58.                 9.7 M
  59. redhat-lsb    x86_64 4.0-7.el6.centos   @anaconda-CentOS-201703281317.x86_64/6.9
  60.                 0.0
  61. redhat-lsb-compat  x86_64 4.0-7.el6.centos   @anaconda-CentOS-201703281317.x86_64/6.9
  62.                 0.0
  63. redhat-lsb-core  x86_64 4.0-7.el6.centos   @anaconda-CentOS-201703281317.x86_64/6.9
  64.                 22 k
  65. redhat-lsb-graphics x86_64 4.0-7.el6.centos   @anaconda-CentOS-201703281317.x86_64/6.9
  66.                 0.0
  67. redhat-lsb-printing x86_64 4.0-7.el6.centos   @anaconda-CentOS-201703281317.x86_64/6.9
  68.                 0.0
  69. sysstat    x86_64 9.0.4-33.el6    @anaconda-CentOS-201703281317.x86_64/6.9
  70.                 826 k
  71. Transaction Summary
  72. ====================================================================
  73. Remove  13 Package(s)
  74. Installed size: 86 M
  75. Is this ok [y/N]: y
  76. Downloading Packages:
  77. Running rpm_check_debug
  78. Running Transaction Test
  79. Transaction Test Succeeded
  80. Running Transaction
  81. Warning: RPMDB altered outside of yum.
  82. Erasing : redhat-lsb-compat-4.0-7.el6.centos.x86_64  1/13
  83. Erasing : redhat-lsb-4.0-7.el6.centos.x86_64    2/13
  84. Erasing : cloudera-manager-agent-5.11.1-1.cm5111.p0.9. 3/13
  85. warning: /etc/cloudera-scm-agent/config.ini saved as /etc/cloudera-scm-agent/config.ini.rpmsave
  86. Erasing : redhat-lsb-graphics-4.0-7.el6.centos.x86_64  4/13
  87. Erasing : redhat-lsb-printing-4.0-7.el6.centos.x86_64  5/13
  88. Erasing : redhat-lsb-core-4.0-7.el6.centos.x86_64   6/13
  89. /var/tmp/rpm-tmp.jLbJUk: line 1: lsb_release: command not found
  90. Erasing : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64   7/13
  91. Erasing : sysstat-9.0.4-33.el6.x86_64      8/13
  92. Erasing : crontabs-1.10-33.el6.noarch      9/13
  93. Erasing : cronie-anacron-1.4.4-16.el6_8.2.x86_64   10/13
  94. Erasing : cronie-1.4.4-16.el6_8.2.x86_64     11/13
  95. Erasing : 2:postfix-2.6.6-8.el6.x86_64     12/13
  96. Erasing : mysql-libs-5.1.73-8.el6_8.x86_64    13/13
  97. Verifying : redhat-lsb-printing-4.0-7.el6.centos.x86_64  1/13
  98. Verifying : cronie-anacron-1.4.4-16.el6_8.2.x86_64   2/13
  99. Verifying : cronie-1.4.4-16.el6_8.2.x86_64     3/13
  100. Verifying : 2:postfix-2.6.6-8.el6.x86_64     4/13
  101. Verifying : redhat-lsb-4.0-7.el6.centos.x86_64    5/13
  102. Verifying : redhat-lsb-core-4.0-7.el6.centos.x86_64   6/13
  103. Verifying : cloudera-manager-agent-5.11.1-1.cm5111.p0.9. 7/13
  104. Verifying : crontabs-1.10-33.el6.noarch      8/13
  105. Verifying : redhat-lsb-compat-4.0-7.el6.centos.x86_64  9/13
  106. Verifying : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64   10/13
  107. Verifying : redhat-lsb-graphics-4.0-7.el6.centos.x86_64 11/13
  108. Verifying : sysstat-9.0.4-33.el6.x86_64     12/13
  109. Verifying : mysql-libs-5.1.73-8.el6_8.x86_64    13/13
  110. Removed:
  111. MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6      
  112. mysql-libs.x86_64 0:5.1.73-8.el6_8        
  113. Dependency Removed:
  114. cloudera-manager-agent.x86_64 0:5.11.1-1.cm5111.p0.9.el6   
  115. cronie.x86_64 0:1.4.4-16.el6_8.2         
  116. cronie-anacron.x86_64 0:1.4.4-16.el6_8.2      
  117. crontabs.noarch 0:1.10-33.el6         
  118. postfix.x86_64 2:2.6.6-8.el6         
  119. redhat-lsb.x86_64 0:4.0-7.el6.centos        
  120. redhat-lsb-compat.x86_64 0:4.0-7.el6.centos      
  121. redhat-lsb-core.x86_64 0:4.0-7.el6.centos      
  122. redhat-lsb-graphics.x86_64 0:4.0-7.el6.centos      
  123. redhat-lsb-printing.x86_64 0:4.0-7.el6.centos      
  124. sysstat.x86_64 0:9.0.4-33.el6         
  125. Complete!
复制代码
3、用whereis命令查找mysql干系的文件,因为步调2用yum来卸载,所以mysql被清理得很干净;如果利用rpm将会很贫困,有许多的文件必要手动扫除
  1. [root@cdh1 zjl]# whereis mysql
  2. mysql:
复制代码
4、查看系统中的mysql安装包
  1. [root@cdh1 zjl]# yum list mysql*
  2. Loaded plugins: fastestmirror, refresh-packagekit, security
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.zju.edu.cn
  5. * extras: mirrors.aliyun.com
  6. * updates: mirrors.aliyun.com
  7. Available Packages
  8. MySQL-python.x86_64                      1.2.3-0.3.c1.1.el6                    base
  9. mysql.x86_64                        5.1.73-8.el6_8                     base
  10. mysql-bench.x86_64                       5.1.73-8.el6_8                     base
  11. mysql-connector-java.noarch                    1:5.1.17-6.el6                     base
  12. mysql-connector-odbc.x86_64                    5.1.5r1144-7.el6                     base
  13. mysql-devel.i686                       5.1.73-8.el6_8                     base
  14. mysql-devel.x86_64                       5.1.73-8.el6_8                     base
  15. mysql-embedded.i686                      5.1.73-8.el6_8                     base
  16. mysql-embedded.x86_64                      5.1.73-8.el6_8                     base
  17. mysql-embedded-devel.i686                     5.1.73-8.el6_8                     base
  18. mysql-embedded-devel.x86_64                    5.1.73-8.el6_8                     base
  19. mysql-libs.i686                       5.1.73-8.el6_8                     base
  20. mysql-libs.x86_64                       5.1.73-8.el6_8                     base
  21. mysql-server.x86_64                      5.1.73-8.el6_8                     base
  22. mysql-test.x86_64                       5.1.73-8.el6_8                     base
复制代码
5、选择mysql-server来安装
  1. [root@cdh1 zjl]# yum install mysql-server
  2. Loaded plugins: fastestmirror, refresh-packagekit, security
  3. Setting up Install Process
  4. Loading mirror speeds from cached hostfile
  5. * base: mirrors.zju.edu.cn
  6. * extras: mirrors.aliyun.com
  7. * updates: mirrors.aliyun.com
  8. Resolving Dependencies
  9. --> Running transaction check
  10. ---> Package mysql-server.x86_64 0:5.1.73-8.el6_8 will be installed
  11. --> Processing Dependency: mysql = 5.1.73-8.el6_8 for package: mysql-server-5.1.73-8.el6_8.x86_64
  12. --> Processing Dependency: perl-DBI for package: mysql-server-5.1.73-8.el6_8.x86_64
  13. --> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.73-8.el6_8.x86_64
  14. --> Processing Dependency: perl(DBI) for package: mysql-server-5.1.73-8.el6_8.x86_64
  15. --> Processing Dependency: libmysqlclient_r.so.16(libmysqlclient_16)(64bit) for package: mysql-server-5.1.73-8.el6_8.x86_64
  16. --> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: mysql-server-5.1.73-8.el6_8.x86_64
  17. --> Processing Dependency: libmysqlclient_r.so.16()(64bit) for package: mysql-server-5.1.73-8.el6_8.x86_64
  18. --> Processing Dependency: libmysqlclient.so.16()(64bit) for package: mysql-server-5.1.73-8.el6_8.x86_64
  19. --> Running transaction check
  20. ---> Package mysql.x86_64 0:5.1.73-8.el6_8 will be installed
  21. ---> Package mysql-libs.x86_64 0:5.1.73-8.el6_8 will be installed
  22. ---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
  23. ---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
  24. --> Finished Dependency Resolution
  25. Dependencies Resolved
  26. =================================================================================================================================================================================================================
  27. Package            Arch           Version            Repository         Size
  28. =================================================================================================================================================================================================================
  29. Installing:
  30. mysql-server           x86_64           5.1.73-8.el6_8           base           8.6 M
  31. Installing for dependencies:
  32. mysql             x86_64           5.1.73-8.el6_8           base           895 k
  33. mysql-libs            x86_64           5.1.73-8.el6_8           base           1.2 M
  34. perl-DBD-MySQL           x86_64           4.013-3.el6           base           134 k
  35. perl-DBI            x86_64           1.609-4.el6           base           705 k
  36. Transaction Summary
  37. =================================================================================================================================================================================================================
  38. Install  5 Package(s)
  39. Total download size: 12 M
  40. Installed size: 33 M
  41. Is this ok [y/N]:
  42. 6、选择y继续安装
  43. Is this ok [y/N]: y
  44. Downloading Packages:
  45. (1/5): mysql-5.1.73-8.el6_8.x86_64.rpm                                     | 895 kB  00:00  
  46. (2/5): mysql-libs-5.1.73-8.el6_8.x86_64.rpm                                    | 1.2 MB  00:00  
  47. (3/5): mysql-server-5.1.73-8.el6_8.x86_64.rpm                                    | 8.6 MB  00:02  
  48. (4/5): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm                                    | 134 kB  00:00  
  49. (5/5): perl-DBI-1.609-4.el6.x86_64.rpm                                     | 705 kB  00:00  
  50. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  51. Total                                           2.2 MB/s | 12 MB  00:05  
  52. Running rpm_check_debug
  53. Running Transaction Test
  54. Transaction Test Succeeded
  55. Running Transaction
  56. Installing : mysql-libs-5.1.73-8.el6_8.x86_64                                        1/5
  57. Installing : perl-DBI-1.609-4.el6.x86_64                                         2/5
  58. Installing : perl-DBD-MySQL-4.013-3.el6.x86_64                                        3/5
  59. Installing : mysql-5.1.73-8.el6_8.x86_64                                         4/5
  60. Installing : mysql-server-5.1.73-8.el6_8.x86_64                                       5/5
  61. Verifying : perl-DBD-MySQL-4.013-3.el6.x86_64                                        1/5
  62. Verifying : mysql-libs-5.1.73-8.el6_8.x86_64                                        2/5
  63. Verifying : mysql-server-5.1.73-8.el6_8.x86_64                                       3/5
  64. Verifying : mysql-5.1.73-8.el6_8.x86_64                                         4/5
  65. Verifying : perl-DBI-1.609-4.el6.x86_64                                         5/5
  66. Installed:
  67. mysql-server.x86_64 0:5.1.73-8.el6_8                                          
  68. Dependency Installed:
  69. mysql.x86_64 0:5.1.73-8.el6_8     mysql-libs.x86_64 0:5.1.73-8.el6_8     perl-DBD-MySQL.x86_64 0:4.013-3.el6     perl-DBI.x86_64 0:1.609-4.el6     
  70. Complete!
复制代码
7、启动mysql服务
  1. [root@cdh1 zjl]# service mysqld start
  2. Initializing MySQL database: Installing MySQL system tables...
  3. OK
  4. Filling help tables...
  5. OK
  6. To start mysqld at boot time you have to copy
  7. support-files/mysql.server to the right place for your system
  8. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  9. To do so, start the server, then issue the following commands:
  10. /usr/bin/mysqladmin -u root password 'new-password'
  11. /usr/bin/mysqladmin -u root -h cdh1.zjl.com password 'new-password'
  12. Alternatively you can run:
  13. /usr/bin/mysql_secure_installation
  14. which will also give you the option of removing the test
  15. databases and anonymous user created by default. This is
  16. strongly recommended for production servers.
  17. See the manual for more instructions.
  18. You can start the MySQL daemon with:
  19. cd /usr ; /usr/bin/mysqld_safe &
  20. You can test the MySQL daemon with mysql-test-run.pl
  21. cd /usr/mysql-test ; perl mysql-test-run.pl
  22. Please report any problems with the /usr/bin/mysqlbug script!
  23.                [ OK ]
  24. Starting mysqld:           [ OK ]
复制代码
8、连接一下试一下,直接mysql然后\q关闭连接
  1. [root@cdh1 zjl]# mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 2
  4. Server version: 5.1.73 Source distribution
  5. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> \q
  11. Bye
复制代码
9、设置mysql开机启动
  1. [root@cdh1 zjl]# chkconfig mysqld on
复制代码
10、开启3306端口,并保存
  1. [root@cdh1 zjl]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
  2. [root@cdh1 zjl]# /etc/rc.d/init.d/iptables save
复制代码
11、连接mysql设置暗码
  1. [root@cdh1 zjl]# mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 3
  4. Server version: 5.1.73 Source distribution
  5. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> use mysql;
  11. Reading table information for completion of table and column names
  12. You can turn off this feature to get a quicker startup with -A
  13. Database changed
  14. mysql> update user set password=password('123') where user='root';
  15. Query OK, 3 rows affected (0.02 sec)
  16. Rows matched: 3 Changed: 3 Warnings: 0
  17. mysql> flush privileges;
  18. Query OK, 0 rows affected (0.02 sec)
  19. mysql> \q
  20. Bye
复制代码
12、重启mysql服务
  1. [root@cdh1 zjl]# service mysqld restart
  2. Stopping mysqld:           [ OK ]
  3. Starting mysqld:           [ OK ]
复制代码
以上所述是小编给各人先容的centos 6.9安装mysql的具体教程,希望对各人有所帮助,如果各人有任何疑问请给我留言,小编会及时回复各人的。在此也非常感谢各人对脚本之家网站的支持!

帖子地址: 

回复

使用道具 举报

分享
推广
火星云矿 | 预约S19Pro,享500抵1000!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

草根技术分享(草根吧)是全球知名中文IT技术交流平台,创建于2021年,包含原创博客、精品问答、职业培训、技术社区、资源下载等产品服务,提供原创、优质、完整内容的专业IT技术开发社区。
  • 官方手机版

  • 微信公众号

  • 商务合作