1.系统版本
[root@test001 ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
[root@test001 ~]#
2.查看有无Mariadb的包,并卸载它
[root@test001 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
[root@test001 ~]# rpm -e mariadb-libs-5.5.65-1.el7.x86_64 --nodeps
3.下载mysql rpm的官方yum源
[root@test001 ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@test001 ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
[root@test001 ~]# yum -y install mysql-community-server
配置MySQL
[root@test001 ~]# systemctl start mysqld.service
[root@test001 ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2021-12-05 16:29:12 CST; 30s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 3939 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 3881 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 3942 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─3942 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
12月 05 16:29:07 test001 systemd[1]: Starting MySQL Server...
12月 05 16:29:12 test001 systemd[1]: Started MySQL Server.
[root@test001 ~]#
找出MySQL的密码:
[root@test001 ~]# grep "password" /var/log/mysqld.log
2021-12-05T08:29:10.359197Z 1 [Note] A temporary password is generated for root@localhost: *********
[root@test001 ~]#
此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库
其中‘new password’替换成你要设置的密码,注意:密码设置必须要大小写字母数字和特殊符号(,/';:等),不然不能配置成功
开启mysql的远程访问 执行以下命令开启远程访问限制,我开启的是允许所有用户访问
4.关闭防火墙
[root@test001 ~]# systemctl stop firewalld
[root@test001 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@test001 ~]#
[root@test001 ~]# vi /etc/selinux/config
重启服务器。
[root@test001 ~]# systemctl start mysqld
[root@test001 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2021-12-05 16:43:22 CST; 1min 54s left
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 1389 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 1030 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 1392 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─1392 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
12月 05 16:43:19 test001 systemd[1]: Starting MySQL Server...
12月 05 16:43:22 test001 systemd[1]: Started MySQL Server.
5.更改MySQL的语言
修改/etc/my.cnf文件
[root@test001 ~]# vi /etc/my.cnf
[client]
default-character-set=utf8
//dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
collation-server=utf8_general_ci
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@test001 etc]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@test001 etc]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2021-12-05 17:20:34 CST; 8s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 21278 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 21256 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 21281 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─21281 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
12月 05 17:20:33 test001 systemd[1]: Stopped MySQL Server.
12月 05 17:20:33 test001 systemd[1]: Starting MySQL Server...
12月 05 17:20:34 test001 systemd[1]: Started MySQL Server.
[root@test001 etc]#
再次看看字符集有无更改: