linux系统mysql安装和卸载

安装mysql5.7

安装wget: yum install wget

  1. 载mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

  1. 安装mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

  1. 安装mysql

yum install mysql-server

修改密码

刚安装的mysql,没有设置密码,可以直接进入数据库修改,步骤如下

  1. mysql -uroot -p
  2. use mysql;
  3. update user set password=password(“test”) where user=’root’;
  4. flush privileges;
  5. exit;

设置远程权限

可以先自己测试一下远程是否可以用,有的可以不用设置,默认已经开发权限

1.将3306端口加入防火墙

/sbin/iptables -I INPUT -p tcp –dport 3306-j ACCEPT #添加端口3306

/etc/rc.d/init.d/iptables save #保存设置

/etc/rc.d/init.d/iptables status #查看防火墙状态

  1. 设置远程访问权限

mysql -u root -p password //进入mysql控制台

mysql>use mysql;

mysql>update user set host = ‘%’ where user = ‘root’; //这个命令执行错误时可略过

mysql>flush privileges;

mysql>select host, user from user; //检查‘%’ 是否插入到数据库中

mysql>quit

卸载MYSQL

  1. 查看当前安装mysql情况 rpm -qa|grep -i mysql

mysql-community-client-5.6.37-2.el6.x86_64
mysql-community-release-el6-5.noarch
mysql-community-libs-5.6.37-2.el6.x86_64
mysql-community-server-5.6.37-2.el6.x86_64
mysql-community-common-5.6.37-2.el6.x86_64

  1. 删除上面的 rpm -e –noscripts {已经安装的}

rpm -ev mysql-community-server-5.6.37-2.el6.x86_64
rpm -ev mysql-community-client-5.6.37-2.el6.x86_64
rpm -ev mysql-community-release-el6-5.noarch
rpm -ev –nodeps mysql-community-common-5.6.37-2.el6.x86_64
rpm -ev –nodeps mysql-community-libs-5.6.37-2.el6.x86_64

3.找之前老版本mysql的目录

/etc/selinux/targeted/active/modules/100/mysql
/usr/share/mysql
/var/lib/mysql
/var/lib/mysql/mysql

  1. 删除老版本mysql的文件和库 find / -name mysql

rm -rf /etc/selinux/targeted/active/modules/100/mysql

rm -rf /usr/share/mysql
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql

修改权限

  1. 登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:
    $ sudo chown -R root:root /var/lib/mysql
    原文作者:mysql
    原文地址: https://www.jianshu.com/p/5dec32e02d1c
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞