yum 安装卸载mysql

以前做过yum安装卸载mysql的笔记,现在整理到网上,希望对需要的朋友有所帮助

1.下载YUM库

 wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
 或wget --no-check-certificate http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

2.安装YUM库

yum localinstall -y mysql57-community-release-el7-10.noarch.rpm

3.安装数据库

 yum install -y mysql-community-server    

4.启动MySQL服务

systemctl start mysqld.service

5.查找mysql安装时的临时密码

 grep 'password' /var/log/mysqld.log |head -n 1

mysql -uroot -p回车

输入密码

6.修改密码,解决密码安全问题:

如何解决ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误?
解决:必须修改两个全局参数
set global validate_password_policy=0; 
再修改密码的长度:set global validate_password_length=1;

修改密码:SET PASSWORD = PASSWORD('root'); 

7.添加远程登录用户

use mysql;

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

设置防火墙:
1)centos6

vi /etc/sysconfig/iptables

在-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited之前,添加

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

重启防火墙

service iptables restart

2)centos7

启动:# systemctl start  firewalld
查看状态:# systemctl status firewalld 或者 firewall-cmd --state
停止:# systemctl stop firewalld
禁用:# systemctl disable firewalld

8.设置字符编码和区分大小写

SHOW VARIABLES LIKE '%char%';

修改mysql配置文件:vi /etc/my.cnf

[mysqld]

character-set-server=utf8

collation-server=utf8_general_ci
#区分大小写——-0:区分;1:不区分
lower_case_table_names=1

[client]
default-character-set=utf8

9.设置开机自启:
设置开机自动启动
# chkconfig mysqld on  或者  systemctl enable mysqld
# chkconfig --list | grep mysql


升级mysql-server
yum update mysql-server

mysql安装出现的错误:
-bash: mysql: command not found
解决:
# cd /usr/local/bin
# ln -fs /mysql安装路径/bin/mysql mysql


1、yum remove mysql mysql-server mysql-libs compat-mysql51

2、rm -rf /var/lib/mysql

3、rm /etc/my.cnf

查看是否还有mysql软件:
rpm -qa|grep mysql

如果存在的话,继续删除即可。

a)查看系统中是否以rpm包安装的mysql:

 

[root@localhost opt]# rpm -qa | grep -i mysql
MySQL-server-5.6.17-1.el6.i686
MySQL-client-5.6.17-1.el6.i686

 

b)卸载mysql

[root@localhost local]# rpm -e MySQL-server-5.6.17-1.el6.i686
[root@localhost local]# rpm -e MySQL-client-5.6.17-1.el6.i686

c)删除mysql服务

[root@localhost local]# chkconfig --list | grep -i mysql
[root@localhost local]# chkconfig --del mysql

d)删除分散mysql文件夹

[root@localhost local]# whereis mysql 或者 find / -name mysql

 

mysql: /usr/lib/mysql /usr/share/mysql

清空相关mysql的所有目录以及文件
rm -rf /usr/lib/mysql
rm -rf /usr/share/mysql

rm -rf /usr/my.cnf

你可能感兴趣的:(mysql)