centos7下快速安装mysql

时间:2020-12-22 14:45:11

CentOS 7的yum源中貌似没有正常安装MySQL时的mysql-sever文件,需要去官网上下载

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
成功安装之后重启mysql服务
# service mysqld restart

初次安装mysql是root账户是没有密码的

设置密码的方法

# mysql -u root -p

mysql> update mysql.user set password=password('123456') where User="root" and Host="localhost";

mysql> exit

搞定!

远程授权连接mysql

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

FLUSH   PRIVILEGES;

卸载
#列出所有被安装的rpm package
rpm -qa | grep mariadb
强制卸载
rpm -e --nodeps

rpm方式安装的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