目录
卸载
安装
1、关闭MySQL服务
systemctl stop mysqld
2、使用 rpm 命令查看已安装的安装包
[name@VM-20-12-centos mysql1]$ rpm -qa|grep mysql
3、使用yum卸载安装的mysql
[name@VM-20-12-centos mysql1]$ sudo yum remove mysql mysql-server mysql-libs mysql-server
4、查询剩余的安装包
[name@VM-20-12-centos mysql1]$ rpm -qa|grep mysql
5、移除掉这些安装包
[name@VM-20-12-centos mysql1]$ sudo rpm -ev mysql-community-release-el7-5.noarch
[name@VM-20-12-centos mysql1]$ sudo rpm -ev mysql-community-common-5.6.51-2.el7.x86_64
6、检查残余安装包
[name@VM-20-12-centos mysql1]$ ls
7、删除残余的安装包
sudo rm -rf mysql*
8、继续查找是否还有残留文件
[name@VM-20-12-centos mysql1]$ sudo find / -name mysql
9、移除这些残留文件
[name@VM-20-12-centos mysql1]$ sudo rm -rf /etc/selinux/targeted/active/modules/100/mysql
[name@VM-20-12-centos mysql1]$ sudo rm -rf /usr/share/mysql
[name@VM-20-12-centos mysql1]$ sudo rm -rf /var/lib/mysql
[name@VM-20-12-centos mysql1]$ sudo rm -rf /var/lib/mysql/mysql
10.最后检查
[name@VM-20-12-centos mysql1]$ rpm -qa|grep mysql
[name@VM-20-12-centos mysql1]$ sudo find / -name mysql
[name@VM-20-12-centos mysql1]$ ls
1. 下载 MySQL yum包
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
2.安装MySQL源
[name@VM-20-12-centos mysql1]$ sudo rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
3.安装MySQL服务端,需要等待一些时间
[name@VM-20-12-centos mysql1]$ yum -y install mysql-community-server --nogpgcheck
4.启动MySQL
[name@VM-20-12-centos mysql1]$ systemctl start mysqld.service
5.检查是否启动成功
[name@VM-20-12-centos mysql1]$ systemctl status mysqld.service
6.获取临时密码,MySQL5.7为root用户随机生成了一个密码
[name@VM-20-12-centos mysql1]$ sudo grep 'temporary password' /var/log/mysqld.log
7.通过临时密码登录MySQL,进行修改密码操作
[name@VM-20-12-centos mysql1]$ mysql -uroot -p
8.因为MySQL的密码规则需要很复杂,我们一般自己设置的不会设置成这样,所以我们全局修改一下
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
这时候我们就可以自己设置想要的密码了
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
9.授权其他机器远程登录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT
OPTION;
mysql> FLUSH PRIVILEGES;
10.开启开机自启动
先退出mysql命令行,然后输入以下命令
[name@VM-20-12-centos mysql1]$ systemctl enable mysqld
[name@VM-20-12-centos mysql1]$ systemctl daemon-reload
11.设置MySQL的字符集为UTF-8,令其支持中文
[name@VM-20-12-centos mysql1]$ sudo vim /etc/my.cnf
改成如下,然后保存
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysql]
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-storage-engine=INNODB
character_set_server=utf8
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
12.重启一下MySQL,令配置生效
[name@VM-20-12-centos mysql1]$ service mysqld restart
13.确保你在终端命令行可以输入中文
[name@VM-20-12-centos mysql1]$ env |grep LANG
14.数据库的操作
(1)查看mysql是否启动:service mysqld status
启动mysql:service mysqld start
停止mysql:service mysqld stop
重启mysql:service mysqld restart
(2)查看临时密码:grep password /var/log/mysqld.log
查看数据库是否服务起来
[name@VM-20-12-centos mysql1]$ ps ajx | grep mysql
[name@VM-20-12-centos mysql1]$ sudo netstat -nltp
客户端和服务端对应的路径
到这里就安装成功啦!!!赶快开始数据库的学习吧。