我用 LinuxLinux学习之路Linux学习|Gentoo/Arch/FreeBSD

(笔记)CentOS 7 安装与卸载MySQL 5.7跳坑

2017-01-17  本文已影响9146人  MaxZing

先介绍卸载

防止重装

 # 查看yum是否安装过mysql
yum list installed mysql*

如或显示了列表,说明系统中有MySQL


yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-libs-compat mysql-community-server mysql57-community-release
rm -rf /var/lib/mysql  
rm /etc/my.cnf  
 rpm -qa | grep -i mysql  
rpm -e mysql57-community-release-el7-9.noarch
rpm -e mysql-community-server-5.7.17-1.el7.x86_64
rpm -e mysql-community-libs-5.7.17-1.el7.x86_64
rpm -e mysql-community-libs-compat-5.7.17-1.el7.x86_64
rpm -e mysql-community-common-5.7.17-1.el7.x86_64
rpm -e mysql-community-client-5.7.17-1.el7.x86_64
cd /var/lib/  
rm -rf mysql/  
whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
# 删除上面的文件夹
rm -rf /usr/bin/mysql
…
…

我就省略了

rm –rf /usr/my.cnf
rm -rf /root/.mysql_sercret

剩余配置检查

chkconfig --list | grep -i mysql
chkconfig --del mysqld

根据上面的列表,删除 ,如:mysqld

再介绍安装

按照官方的文档进行安装
http://dev.mysql.com/doc/refman/5.7/en/installing.html

http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html
文档地址:http://dev.mysql.com/doc/refman/5.7/en/linux-installation.html
3是各种安装方式列表
CentOS用yum安装相对省事,省去很多配置环节

yum安装,先要搞到源

wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm

接下来使用yum安装

# 更新yum软件包
yum check-update  
# 更新系统 
yum update
 #安装mysql
yum install mysql mysql-server

接下来是漫长的等待。如果中途关机,或者下载挂了,请执行卸载步骤后,再来一次。

完成后

记住要给root上密码

/usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql &
systemctl start mysqld
mysql -u root

mysql> update mysql.user set authentication_string=password('new_password') where user='root' and Host ='localhost';
mysql> flush privileges;
mysql> quit;
systemctl start mysqld
mysql -u root -p
+ 授权远程访问
use mysql;
grant all privileges  on *.* to root@'%' identified by "root";
FLUSH RIVILEGES;

建议root不要授权远程访问,请创建新mysql用户

编译安装

这个略坑,我按照官方文档安装,安好了不会配置,唉,吐槽自己太菜!导致没启动成功,后来换成了yum安装
http://dev.mysql.com/doc/refman/5.7/en/installing-source-distribution.html
我还是要把脚本贴出来

# 添加mysql用户
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> rpmbuild --rebuild --clean MySQL-VERSION.src.rpm
# 源码编译安装
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> mkdir build
shell> cd build
shell> cmake ..
shell> make
shell> make install
# 结束 source-build specific instructions
# 权限步骤
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql    # MySQL 5.7.6执行
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 更高版本执行
shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 更高版本执行
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# 配置命令
shell> cp support-files/mysql.server /etc/init.d/mysql.server

大致是以上的安装脚本,官网上有详细解释每一条的作用。可以参照一下。如果安装失败,可以参照最上面的卸载教程。
祝你好运。

参考

http://dev.mysql.com/doc/
http://blog.csdn.net/typa01_kk/article/details/49057073


如果有错别字或者其他错误,请告知我修改。
转载请务必注明出处!
love&peace

上一篇下一篇

猜你喜欢

热点阅读