Linux 之 CentOS7安装MySQL(yum 源方式)
1.下载mysql源安装包 $ wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 2.安装mysql源 $ yum localinstall mysql57-community-release-el7-8.noarch.rpm 3.检查mysql源是否安装成功 $ yum repolist enabled | grep "mysql.*-community.*" 4.修改yum源 【可跳过】 $ vim /etc/yum.repos.d/mysql-community.repo 改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。 备注:enabled=1表示即将要安装的mysql版本,这个文件也可以不修改,默认安装mysql最高版本 5.安装MySQL 这一步才是真正安装mysql $ yum install mysql-community-server 6.启动MySQL服务并设置开机启动 $ systemctl start mysqld $ systemctl enable mysqld $ systemctl daemon-reload 7.端口开放 $ firewall-cmd --zone=public --add-port=3306/tcp --permanent $ firewall-cmd --reload 8.修改root本地登录密码 1)查看mysql密码 $ grep 'temporary password' /var/log/mysqld.log 2)连接mysql $ mysql -uroot -p 3)修改密码【注意:后面的分号一定要跟上】 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 或者: mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); mysql> show variables like '%password%'; 9.添加远程登录用户 mysql> GRANT ALL PRIVILEGES ON *.* TO 'caoxiaobo'@'%' IDENTIFIED BY 'Caoxiaobo0917!' WITH GRANT OPTION;
10.sql中使用 truncate 清空表数据时,外键报错解决:
解决方案:
在Mysql中取消外键约束: SET FOREIGN_KEY_CHECKS=0;
执行 truncate tablename
然后再设置外键约束: SET FOREIGN_KEY_CHECKS=1;
11、linux下卸载mysql
yum list installed | grep mysql ---->查看已经安装的mysql插件
yum remove -y mysql80-community-release.noarch mysql-community-client mysql-community-server mysql-community-common mysql-community-libs
(remove -y 后面跟的是上一条命令查出来的安装的插件的包名)
世间安得双全法,不负如来不负卿