CentOS 6.9安装MySQL 5.1.73
分享在 CentOS 6.9 环境中安装 MySQL 5.1.73 数据库,希望对大家有所帮助。
1、确认 mysql 是否已安装,有下面的代码可知
[root@cdh1 linuxidc]#yumlist installed mysql*
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
*base: mirrors.zju.edu.cn
*extras: mirrors.aliyun.com
*updates: mirrors.aliyun.com
Installed Packages
MySQL-python.x86_641.2.3-0.3.c1.1.el6 @base
mysql-libs.x86_64 5.1.73-8.el6_8 @anaconda-CentOS-201703281317.x86_64/6.9
2、卸载已安装的 mysql,建议使用 yum 命令,因为 yum 命令可以自动删除与 mysql 相关的依赖;如果使用 rpm 命令,则还需要手动去删除和 mysql 相关的文件,比较麻烦
[root@cdh1 linuxidc]#yumremove MySQL-python.x86_64 mysql-libs.x86_64
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Remove Process
Resolving Dependencies
-->Running transaction check
---> Package MySQL-python.x86_640:1.2.3-0.3.c1.1.el6 will be erased
--> Processing Dependency: MySQL-pythonforpackage: cloudera-manager-agent-5.11.1-1.cm5111.p0.9.el6.x86_64
---> Package mysql-libs.x86_640:5.1.73-8.el6_8 will be erased
--> Processing Dependency: libmysqlclient.so.16()(64bit)forpackage:2:postfix-2.6.6-8.el6.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit)forpackage:2:postfix-2.6.6-8.el6.x86_64
--> Processing Dependency: mysql-libsforpackage:2:postfix-2.6.6-8.el6.x86_64
-->Running transaction check
---> Package cloudera-manager-agent.x86_640:5.11.1-1.cm5111.p0.9.el6 will be erased
---> Package postfix.x86_642:2.6.6-8.el6 will be erased
--> Processing Dependency: /usr/sbin/sendmailforpackage:RedHat-lsb-core-4.0-7.el6.centos.x86_64
--> Processing Dependency: /usr/sbin/sendmailforpackage: cronie-1.4.4-16.el6_8.2.x86_64
-->Running transaction check
---> Package cronie.x86_640:1.4.4-16.el6_8.2will be erased
--> Processing Dependency: cronie =1.4.4-16.el6_8.2 forpackage: cronie-anacron-1.4.4-16.el6_8.2.x86_64
---> Package redhat-lsb-core.x86_640:4.0-7.el6.centos will be erased
--> Processing Dependency: redhat-lsb-core(x86-64) =4.0 forpackage: redhat-lsb-printing-4.0-7.el6.centos.x86_64
--> Processing Dependency: redhat-lsb-core(x86-64) =4.0-7.el6.centosforpackage: redhat-lsb-4.0-7.el6.centos.x86_64
--> Processing Dependency: redhat-lsb-core(x86-64) =4.0 forpackage: redhat-lsb-graphics-4.0-7.el6.centos.x86_64
-->Running transaction check
---> Package cronie-anacron.x86_640:1.4.4-16.el6_8.2will be erased
---> Package redhat-lsb.x86_640:4.0-7.el6.centos will be erased
--> Processing Dependency: redhat-lsb(x86-64) =4.0-7.el6.centosforpackage: redhat-lsb-compat-4.0-7.el6.centos.x86_64
---> Package redhat-lsb-graphics.x86_640:4.0-7.el6.centos will be erased
---> Package redhat-lsb-printing.x86_640:4.0-7.el6.centos will be erased
-->Running transaction check
---> Package redhat-lsb-compat.x86_640:4.0-7.el6.centos will be erased
--> Processing Dependency: /etc/cron.dforpackage: crontabs-1.10-33.el6.noarch
--> Processing Dependency: /etc/cron.dforpackage: sysstat-9.0.4-33.el6.x86_64
-->Restarting Dependency Resolution with new changes.
-->Running transaction check
---> Package crontabs.noarch0:1.10-33.el6 will be erased
---> Package sysstat.x86_640:9.0.4-33.el6 will be erased
-->Finished Dependency Resolution
Dependencies Resolved
====================================================================
Package Arch Version Repository
Size
====================================================================
Removing:
MySQL-python x86_641.2.3-0.3.c1.1.el6 @base246k
mysql-libs x86_645.1.73-8.el6_8 @anaconda-CentOS-201703281317.x86_64/6.9
4.0M
Removingfordependencies:
cloudera-manager-agent x86_645.11.1-1.cm5111.p0.9.el6 @/cloudera-manager-agent-5.11.1-1.cm5111.p0.9.el6.x86_64
71M
cronie x86_641.4.4-16.el6_8.2@anaconda-CentOS-201703281317.x86_64/6.9
174k
cronie-anacron x86_641.4.4-16.el6_8.2@anaconda-CentOS-201703281317.x86_64/6.9
43k
crontabs noarch1.10-33.el6 @anaconda-CentOS-201703281317.x86_64/6.9
2.4k
postfix x86_642:2.6.6-8.el6 @anaconda-CentOS-201703281317.x86_64/6.9
9.7M
redhat-lsb x86_644.0-7.el6.centos @anaconda-CentOS-201703281317.x86_64/6.9
0.0
redhat-lsb-compat x86_644.0-7.el6.centos @anaconda-CentOS-201703281317.x86_64/6.9
0.0
redhat-lsb-core x86_644.0-7.el6.centos @anaconda-CentOS-201703281317.x86_64/6.9
22k
redhat-lsb-graphics x86_644.0-7.el6.centos @anaconda-CentOS-201703281317.x86_64/6.9
0.0
redhat-lsb-printing x86_644.0-7.el6.centos @anaconda-CentOS-201703281317.x86_64/6.9
0.0
sysstat x86_649.0.4-33.el6 @anaconda-CentOS-201703281317.x86_64/6.9
826k
Transaction Summary
====================================================================
Remove 13Package(s)
Installed size:86M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside ofyum.
Erasing : redhat-lsb-compat-4.0-7.el6.centos.x86_64 1/13
Erasing : redhat-lsb-4.0-7.el6.centos.x86_64 2/13
Erasing : cloudera-manager-agent-5.11.1-1.cm5111.p0.9. 3/13
warning:/etc/cloudera-scm-agent/config.ini saved as /etc/cloudera-scm-agent/config.ini.rpmsave
Erasing : redhat-lsb-graphics-4.0-7.el6.centos.x86_64 4/13
Erasing : redhat-lsb-printing-4.0-7.el6.centos.x86_64 5/13
Erasing : redhat-lsb-core-4.0-7.el6.centos.x86_64 6/13
/var/tmp/rpm-tmp.jLbJUk: line1: lsb_release: command not found
Erasing : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 7/13
Erasing : sysstat-9.0.4-33.el6.x86_64 8/13
Erasing : crontabs-1.10-33.el6.noarch 9/13
Erasing : cronie-anacron-1.4.4-16.el6_8.2.x86_64 10/13
Erasing : cronie-1.4.4-16.el6_8.2.x86_64 11/13
Erasing :2:postfix-2.6.6-8.el6.x86_64 12/13
Erasing : mysql-libs-5.1.73-8.el6_8.x86_64 13/13
Verifying : redhat-lsb-printing-4.0-7.el6.centos.x86_64 1/13
Verifying : cronie-anacron-1.4.4-16.el6_8.2.x86_64 2/13
Verifying : cronie-1.4.4-16.el6_8.2.x86_64 3/13
Verifying :2:postfix-2.6.6-8.el6.x86_64 4/13
Verifying : redhat-lsb-4.0-7.el6.centos.x86_64 5/13
Verifying : redhat-lsb-core-4.0-7.el6.centos.x86_64 6/13
Verifying : cloudera-manager-agent-5.11.1-1.cm5111.p0.9. 7/13
Verifying : crontabs-1.10-33.el6.noarch 8/13
Verifying : redhat-lsb-compat-4.0-7.el6.centos.x86_64 9/13
Verifying : MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 10/13
Verifying : redhat-lsb-graphics-4.0-7.el6.centos.x86_64 11/13
Verifying : sysstat-9.0.4-33.el6.x86_64 12/13
Verifying : mysql-libs-5.1.73-8.el6_8.x86_64 13/13
Removed:
MySQL-python.x86_640:1.2.3-0.3.c1.1.el6
mysql-libs.x86_640:5.1.73-8.el6_8
Dependency Removed:
cloudera-manager-agent.x86_640:5.11.1-1.cm5111.p0.9.el6
cronie.x86_640:1.4.4-16.el6_8.2
cronie-anacron.x86_640:1.4.4-16.el6_8.2
crontabs.noarch0:1.10-33.el6
postfix.x86_642:2.6.6-8.el6
redhat-lsb.x86_640:4.0-7.el6.centos
redhat-lsb-compat.x86_640:4.0-7.el6.centos
redhat-lsb-core.x86_640:4.0-7.el6.centos
redhat-lsb-graphics.x86_640:4.0-7.el6.centos
redhat-lsb-printing.x86_640:4.0-7.el6.centos
sysstat.x86_640:9.0.4-33.el6
Complete!
3、用 whereis 命令查找 mysql 相关的文件,因为步骤 2 用 yum 来卸载,所以 mysql 被清理得很干净;如果使用 rpm 将会很麻烦,有很多的文件需要手动清除
- [root@cdh1 linuxidc]#whereis mysql mysql:
4、查看系统中的 mysql 安装包
[root@cdh1 linuxidc]#yumlist mysql*
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
*base: mirrors.zju.edu.cn
*extras: mirrors.aliyun.com
*updates: mirrors.aliyun.com
Available Packages
MySQL-python.x86_64 1.2.3-0.3.c1.1.el6 base
mysql.x86_64 5.1.73-8.el6_8 base
mysql-bench.x86_64 5.1.73-8.el6_8 base
mysql-connector-java.noarch 1:5.1.17-6.el6 base
mysql-connector-odbc.x86_64 5.1.5r1144-7.el6 base
mysql-devel.i686 5.1.73-8.el6_8 base
mysql-devel.x86_64 5.1.73-8.el6_8 base
mysql-embedded.i686 5.1.73-8.el6_8 base
mysql-embedded.x86_64 5.1.73-8.el6_8 base
mysql-embedded-devel.i686 5.1.73-8.el6_8 base
mysql-embedded-devel.x86_64 5.1.73-8.el6_8 base
mysql-libs.i686 5.1.73-8.el6_8 base
mysql-libs.x86_64 5.1.73-8.el6_8 base
mysql-server.x86_64 5.1.73-8.el6_8 base
mysql-test.x86_64 5.1.73-8.el6_8 base
5、选择 mysql-server 来安装
[root@cdh1 linuxidc]#yum installmysql-server
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
*base: mirrors.zju.edu.cn
*extras: mirrors.aliyun.com
*updates: mirrors.aliyun.com
Resolving Dependencies
-->Running transaction check
---> Package mysql-server.x86_640:5.1.73-8.el6_8 will be installed
--> Processing Dependency: mysql =5.1.73-8.el6_8forpackage: mysql-server-5.1.73-8.el6_8.x86_64
--> Processing Dependency:perl-DBIforpackage: mysql-server-5.1.73-8.el6_8.x86_64
--> Processing Dependency:perl-DBD-MySQLforpackage: mysql-server-5.1.73-8.el6_8.x86_64
--> Processing Dependency:perl(DBI)forpackage: mysql-server-5.1.73-8.el6_8.x86_64
--> Processing Dependency: libmysqlclient_r.so.16(libmysqlclient_16)(64bit)forpackage: mysql-server-5.1.73-8.el6_8.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit)forpackage: mysql-server-5.1.73-8.el6_8.x86_64
--> Processing Dependency: libmysqlclient_r.so.16()(64bit)forpackage: mysql-server-5.1.73-8.el6_8.x86_64
--> Processing Dependency: libmysqlclient.so.16()(64bit)forpackage: mysql-server-5.1.73-8.el6_8.x86_64
-->Running transaction check
---> Package mysql.x86_640:5.1.73-8.el6_8 will be installed
---> Package mysql-libs.x86_640:5.1.73-8.el6_8 will be installed
---> Packageperl-DBD-MySQL.x86_640:4.013-3.el6 will be installed
---> Packageperl-DBI.x86_640:1.609-4.el6 will be installed
-->Finished Dependency Resolution
Dependencies Resolved
================================================================================================================================================================================================================= Package Arch Version Repository Size=================================================================================================================================================================================================================
Installing:
mysql-server x86_64 5.1.73-8.el6_8 base 8.6M
Installingfordependencies:
mysql x86_64 5.1.73-8.el6_8 base 895k
mysql-libs x86_64 5.1.73-8.el6_8 base 1.2M
perl-DBD-MySQL x86_64 4.013-3.el6 base 134k
perl-DBI x86_64 1.609-4.el6 base 705k
Transaction Summary
=================================================================================================================================================================================================================
Install 5Package(s)
Total download size:12M
Installed size:33M
Is this ok [y/N]:
6、选择 y 继续安装
Is this ok [y/N]: y
Downloading Packages:
(1/5): mysql-5.1.73-8.el6_8.x86_64.rpm |895kB 00:00
(2/5): mysql-libs-5.1.73-8.el6_8.x86_64.rpm |1.2MB 00:00
(3/5): mysql-server-5.1.73-8.el6_8.x86_64.rpm |8.6MB 00:02
(4/5):perl-DBD-MySQL-4.013-3.el6.x86_64.rpm |134kB 00:00
(5/5):perl-DBI-1.609-4.el6.x86_64.rpm |705kB 00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.2MB/s | 12MB 00:05
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : mysql-libs-5.1.73-8.el6_8.x86_64 1/5
Installing :perl-DBI-1.609-4.el6.x86_64 2/5
Installing :perl-DBD-MySQL-4.013-3.el6.x86_64 3/5
Installing : mysql-5.1.73-8.el6_8.x86_64 4/5
Installing : mysql-server-5.1.73-8.el6_8.x86_64 5/5
Verifying :perl-DBD-MySQL-4.013-3.el6.x86_64 1/5
Verifying : mysql-libs-5.1.73-8.el6_8.x86_64 2/5
Verifying : mysql-server-5.1.73-8.el6_8.x86_64 3/5
Verifying : mysql-5.1.73-8.el6_8.x86_64 4/5
Verifying :perl-DBI-1.609-4.el6.x86_64 5/5
Installed:
mysql-server.x86_640:5.1.73-8.el6_8 Dependency Installed: mysql.x86_640:5.1.73-8.el6_8 mysql-libs.x86_640:5.1.73-8.el6_8 perl-DBD-MySQL.x86_640:4.013-3.el6 perl-DBI.x86_640:1.609-4.el6
Complete!
7、启动 mysql 服务
[root@cdh1 linuxidc]# service mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boottimeyou have to copy
support-files/mysql.server to the right placeforyour system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER!
Todoso, start the server,thenissue the following commands:
/usr/bin/mysqladmin -u root password'new-password'
/usr/bin/mysqladmin -u root -h cdh1.linuxidc.com password'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
whichwill also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommendedforproduction servers.
See the manualfor moreinstructions.
You can start the MySQL daemon with:
cd/usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd/usr/mysql-test ;perlmysql-test-run.pl
Please report any problems with the/usr/bin/mysqlbug script!
[OK]
Starting mysqld: [OK]
8、连接一下试一下,直接 mysql 然后 \ q 关闭连接
[root@cdh1 linuxidc]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionidis2
Server version:5.1.73Source distribution
Copyright (c)2000,2013,Oracleand/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' forhelp. Type'\c'toclearthe current input statement.
mysql>\q
Bye
9、设置 mysql 开机启动
- [root@cdh1 linuxidc]#chkconfig mysqld on
10、开启 3306 端���,并保存
- [root@cdh1 linuxidc]# / sbin / iptables - I INPUT - p tcp--dport 3306 - j ACCEPT[root@cdh1 linuxidc]# / etc / rc.d / init.d / iptables save
11、连接 mysql 设置密码
[root@cdh1 linuxidc]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connectionidis3
Server version:5.1.73Source distribution
Copyright (c)2000,2013, 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' forhelp. Type'\c'toclearthe current input statement.
mysql>use mysql;
Reading table informationforcompletion of table and column names
You can turn off this feature to get a quicker startup with-A
Database changed
mysql> update user set password=password('123') where user='root';
Query OK,3rows affected (0.02sec)
Rows matched:3Changed:3Warnings:0
mysql>flush privileges;
Query OK,0rows affected (0.02sec)
mysql>\q
Bye
12、重启 mysql 服务
- [root@cdh1 linuxidc]#service mysqld restart Stopping mysqld: [OK] Starting mysqld: [OK]
来源: http://www.linuxidc.com/Linux/2017-07/145447.htm