Linux 安装(重装)mysql
1 新建存放mysql相关文件的文件夹
mkdir -p /export/servers/mysql //存放mysql相关的几个rpm文件
2 查看原有mysql 并卸载
rpm -qa | grep mysql //查看
mysql-libs-5.1.73-8.el6_8.x86_64等等等等
rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64 //卸载已存在 注意:以此为例 只卸载该版本的东西 类似5.1...的 如果有mysql-python-1.2.5..之类的 不要卸载
如果原来已经安装了mysql,删除mysql目录:
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql
rm -rf /usr/lib64/mysql
rm -rf /etc/my.cnf
3 安装mysql
下载相关文件:
https://dev.mysql.com/downloads/mysql/
选择版本后:
点击这个下载:
跳转到这个页面:
cd /export/servers/mysql //进入mysql相关安装文件的文件夹
wget https://dev.mysql.com/get/+要下载的版本rpm路径 //如果需要安装特定版本 可自行更改下载地址中的版本号
如:wget https://dev.mysql.com/get/MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar
tar -xvf MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar //解压
rm -rf MySQL-5.6.42-1.el7.x86_64.rpm-bundle.tar //删除
rpm -ivh *.rpm //执行安装
如果是centos7可能会报错
warning: MySQL-client-5.6.42-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
perl(Data::Dumper) is needed by MySQL-server-5.6.42-1.el7.x86_64
mariadb-libs is obsoleted by MySQL-shared-compat-5.6.42-1.el7.x86_64
perl(Data::Dumper) is needed by MySQL-test-5.6.42-1.el7.x86_64
卸载mariadb安装perl再次安装mysql即可
rpm -qa | grep mariadb
mariadb-libs-5.5.41-2.el7_0.x86_64
rpm -e --nodeps mariadb-libs-5.5.41-2.el7_0.x86_64
yum install -y perl-Data-Dumper
4 查看并修改随机密码
cat /root/.mysql_secret //查看密码 service mysql start //启动
5 设置系统启动时自动启动mysql服务
chkconfig --add mysql chkconfig mysql on chkconfig //查看
6 设置允许远程访问
mysql -uroot -p pasword: //进入mysql
SET PASSWORD = PASSWORD('root') //修改密码
grant all privileges on *.* to 'root' @'%' identified by 'root'; flush privileges; //刷新