转载源博地址:https://segmentfault.com/a/1190000003049498
Step1: 检测系统是否自带安装mysql
# yum list installed | grep mysql
Step2: 删除系统自带的mysql及其依赖
命令:
# yum -y remove mysql-libs.x86_64
Step3: 给CentOS添加rpm源,并且选择较新的源
命令:
# wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
# yum localinstall mysql-community-release-el6-5.noarch.rpm
# yum repolist all | grep mysql
# yum-config-manager --disable mysql55-community
# yum-config-manager --disable mysql56-community
# yum-config-manager --enable mysql57-community-dmr
# yum repolist enabled | grep mysql
注:如果报错:yum-config-manager: command not found
,这个是因为系统默认没有安装这个命令,这个命令在yum-utils 包里,可以通过命令
yum -y install yum-utils 安装就可以了。
Step4:安装mysql 服务器
命令:
# yum install mysql-community-server
注意:这里可能会报错
NO more mirrors to try
解决措施:输入一下命令
1.yum clean all |
Step5: 启动mysql
命令:
# service mysqld start
可能会报错:
Initializing MySQL database: [FAILED]
解决措施:
service mysql start出错,mysql启动不了,解决mysql: unrecognized service错误的方法如下:
[root@ctohome.com ~]# service mysql start
mysql: unrecognized service
[root@ctohome.com ~]# service mysql restart
mysql: unrecognized service
[root@ctohome.com ~]# rpm -q mysql 查询发现mysql已经正常安装
mysql-5.1.52-jason.1
[root@ctohome.com ~]# /etc/rc.d/init.d/mysqld start 直接启动没问题
Starting mysqld: [ OK ]
[root@ctohome.com ~]# ls /etc/rc.d/init.d/mysqld -l
-rwxr-xr-x 1 root root 5509 Dec 18 02:31 /etc/rc.d/init.d/mysqld
[root@ctohome.com ~]# chkconfig mysqld on 设置mysql开机启动
[root@ctohome.com ~]# chmod 755 /etc/rc.d/init.d/mysqld 修改mysqld执行权限
[root@ctohome.com ~]# service mysqld start 搞定
Starting mysqld: [ OK ]
[root@ctohome.com ~]# service mysqld start
Starting mysqld: [ OK ]
[root@ctohome.com ~]# service mysqld status
mysqld (pid 9487) is running...
Step6: 查看mysql是否自启动,并且设置开启自启动
命令:
# chkconfig --list | grep mysqld
# chkconfig mysqld on
Step7: mysql安全设置
命令:
# mysql_secure_installation