最简单的mysql安装
前期准备
清除centos7会自带mariadb:
rpm -qa |grep -i mysql 查看是否安装了mysql -i忽略大小写
rpm -qa |grep -i mariadb(centos7默认系统自带的)快捷命令:yum -y remove `rpm -qa |grep -i mariadb`
rpm -e 加上包名卸载,如果失败用:yum -y remove mariadb-libs-5.5.68-1.el7.x86_64
安装
- 下载源
cd /usr/local/src && wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
yum -y install mysql80-community-release-el7-7.noarch.rpm
查看安装效果yum repolist enabled | grep mysql.*
-
安装
yum install mysql-community-server -y
-
启动
systemctl start mysqld.service
-
如需修改端口
sed 's|\(\[mysqld\]\)|\1\nport=你的端口\n# skip_grant_tables|' /etc/my.cnf
上述命令确定没问题了,加选项-i
生效 -
防火墙允许新设置端口 并 生效(未开防火墙不用)
firewall-cmd --zone=public --add-port=你的端口/tcp --permanent && firewall-cmd --reload && service mysqld start
或#iptables -A INPUT -ptcp --dport 你的端口 -j ACCEPT
进入
mysql -uroot -p
查看临时密码:grep 'temporary password' /var/log/mysqld.log “localhost:”后的就是
进入后执行:
-
修改密码规则(需修改密码规则,否则简易密码不能通过)
use mysql;set global validate_password.policy=0;set global validate_password.length=1;
-
设置密码
ALTER USER USER() IDENTIFIED BY 'yourpassword';
执行设置向导(可不进行)
mysql_secure_installation
1)输入初始密码,回车
2)设置密码(略)
3)移除匿名用户?y
4)是否允许root远程登录?(默认不允许) n n表示允许
5)是否移除测试库?n
6)重新加载权限表?y
mysql设置
- 允许远程登录并修改密码
use mysql;update user set host='%' where host='localhost';ALTER USER 'root'@'%' IDENTIFIED BY 'yourpassword' PASSWORD EXPIRE NEVER;ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'yourpassword';flush privileges;
exit
service mysqld restart
其他
数据库存储目录:/var/lib/mysql
配置文件:/etc/my.cnf