下载地址:https://downloads.mysql.com/archives/community/
2.1卸载mariadb相关的软件
yum remove -y `rpm -aq mariadb*`2.2删除数据目录和配置文件
rm -rf /etc/my.cnf
rm -rf /var/lib/mysql2.3测试:
rpm -aq mariadb*3.1检查是否有以下两个依赖:
rpm -qa|grep libaio
rpm -qa|grep net-tools3.2顺序执行以下安装命令
rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm3.3服务初始化:
mysqld --initialize --user=mysql3.4查看密码:
grep 'temporary password' /var/log/mysqld.log或者cat /var/log/mysqld.log...
2022-06-28T09:21:01.717228Z 1 [Note] A temporary password is generated for root@localhost: eQjt3T7aXh+(
3.5启动、停止、重启、查看MySQL服务:
systemctl start mysqld
systemctl stop mysqld
systemctl restart mysqld
systemctl status mysqld3.6查看进程:
ps -ef |grep -i mysql3.7查看是否开机自启动(默认安装完已经加入开机自启动):
systemctl list-unit-files|grep mysqld.servicemysqld.service enabled
3.8手动关闭、开启MySQL开机自启动:
systemctl disable mysqld.service
systemctl enable mysqld.service4.1首次登陆(回车后输入刚才查看到的密码,比如本案例是“eQjt3T7aXh+(”):
mysql -uroot -p4.2设置密码的验证强度等级和长度
mysql> set global validate_password_policy=LOW;
mysql> set global validate_password_length=6;4.3修改root默认密码,并设置允许root远程访问
mysql> set password=password('111111');Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all on *.* to root@"%" identified by "111111";Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
mysql> use mysql;
mysql> select Host,User from user;4.4远程连接成功。如果远程连接不上,请关闭防火墙或者开放端口。
关闭防火墙:
systemctl start firewalld.service
systemctl status firewalld.service
systemctl stop firewalld.service
systemctl enable firewalld.service
systemctl disable firewalld.service开放端口:
firewall-cmd --list-all
firewall-cmd --add-service=http --permanent
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload5.1查看默认字符集:
mysql> show variables like 'character%';MySQL5.7以及以下版本默认字符集latin1 不支持中文,建表语句如果不设置字符集,默认就是latin1,保险起见还是手动改一下配置。而MySQL5.8默认已经是utf8mb4
5.2修改默认字符集为utf8mb4
vi /etc/my.cnf在[mysqld]节点下加入下边这一行配置
character_set_server=utf8重启MySQL服务:
systemctl restart mysqld重新登录MySQL并查看字符集,已经全部改为utf8:
mysql> show variables like "%char%";默认情况下,windows系统默认大小写不敏感 ,但是 linux系统是大小写敏感的 。
查看状态:
mysql> show variables like '%lower_case_table_names%';更改状态(可选,根据你的项目需要,比如带有大小写字母的订单号字段):
vi /etc/my.cnf在[mysqld]下加入下边这一行配置(0=大小写敏感,1=大小写不敏感)
lower_case_table_names=1
| 留言与评论(共有 0 条评论) “” |