#在看看能不能正常⼯作[sz@VM-0-3-centos 9.9]$ yum list |grep mysql
Repository epel is listed more than once in the configuration
mysql57-community-release.noarch el7-10 installed
akonadi-mysql.x86_64 1.9.2-4.el7 base
anope-mysql.x86_64 2.0.9-3.el7 epel
apr-util-mysql.x86_64 1.5.2-6.el7 base
calligra-kexi-driver-mysql.x86_64 2.9.10-2.el7 epel
collectd-mysql.x86_64 5.8.1-1.el7 epel
dmlite-plugins-mysql.x86_64 1.14.2-1.el7 epel
dovecot-mysql.x86_64 1:2.2.36-8.el7 base
7. 安装mysql服务
[sz@VM-0-3-centos 9.9]$ sudo yum install -y mysql-community-server
[sudo] password for whb:
Loaded plugins: aliases, auto-update-debuginfo, fastestmirror, protectbase
Repository epel is listed more than once in the configuration
...
Installing : mysql-community-common-5.7.33-1.el7.x86_64 #公共模块
Installing : mysql-community-libs-5.7.33-1.el7.x86_64 #库
Installing : mysql-community-client-5.7.33-1.el7.x86_64 #客⼾端
Installing : mysql-community-server-5.7.33-1.el7.x86_64 #服务器... #安装了服务和客⼾端# 如果报错了,看第16步《常⻅问题》
8. 查看配置⽂件和数据存储位置
[sz@VM-0-3-centos 9.9]$ ls /etc/my.cnf
/etc/my.cnf
[sz@VM-0-3-centos 9.9]$ sudols /var/lib/mysql
.....
9. 启动服务
[sz@VM-0-3-centos 9.9]$ systemctl start mysqld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password:
==== AUTHENTICATION COMPLETE ===
10. 查看启动服务
[sz@VM-0-3-centos 9.9]$ ps axj |grep mysqld
1231832318223182 ? -1 Sl 270:00 /usr/sbin/mysqld --
daemonize --pid-file=/var/run/mysqld/mysqld.pid
13134232432324213134 pts/0 23242 S+ 10050:00 grep --color=auto mysqld
[root@VM-8-9-centos ~]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 000.0.0.0:22 0.0.0.0:* LISTEN 1433/sshd
tcp6 00 :::3306 :::* LISTEN 23642/mysqld
11. 登陆⽅法⼀
#获取临时root密码[sz@VM-0-3-centos 9.9]$ sudogrep'temporary password' /var/log/mysqld.log
2021-04-12T03:23:46.153263Z 1[Note] A temporary password is generated for
root@localhost: yLMalT:v+5l*
#使⽤临时密码登录[sz@VM-0-3-centos 9.9]$ mysql -uroot -p
Enter password:
#判断修改密码时候新密码是否符合当前的策略,不满⾜报错,不让修改,关闭它#安全强度,默认为中,即1,要求必须包含 数字、符号、⼤⼩写字⺟,⻓度⾄少为8位
mysql>set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)#密码最⼩⻓度
mysql>set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)#修改本地登录密码,暂不授权远程登录
mysql> ALTER USER'root'@'localhost' IDENTIFIED BY 'qwer@wu.888';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)#如果你安装的最新的mysql,没有所谓的临时密码,root默认没有密码
[root@bite-alicloud mysql]# vim /etc/my.cnf # 打开mysql配置⽂件
在[mysqld]最后⼀栏配置(不知道是什么,就放在配置⽂件最后) 加⼊: skip-grant-tables 选项,
并保存退出
[root@bite-alicloud mysql]# systemctl restart mysqld # 重启mysql服务# 登陆成功[root@bite-alicloud mysql]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.41 MySQL Community Server (GPL)
Copyright (c)2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.
mysql>
#配置⼀下my.conf,主要是数据库客⼾端和服务器的编码格式[sz@VM-0-3-centos 9.9]$ cat /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 ,暂不设置,mysql有bug,汉字不回显[mysqld]# #
Remove leading # and set to the amount of RAM for the most important data# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.# innodb_buffer_pool_size = 128M# #
Remove leading # to turn on a very important data integrity option: logging# changes to the binary log between backups.# log_bin# #
Remove leading # to set options mainly useful for reporting servers.# The server defaults are faster for transactions and fast SELECTs.# Adjust sizes as needed, experiment to find the optimal values.# join_buffer_size = 128M# sort_buffer_size = 2M# read_rnd_buffer_size = 2Mport=3306datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
og-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character-set-server=utf8
default-storage-engine=innodb
# 配置完毕,重启mysql即可[root@VM-8-9-centos ~]# systemctl stop mysqld[root@VM-8-9-centos ~]# systemctl start mysqld[root@VM-8-9-centos ~]# systemctl restart mysqld
16. 常见问题
mysql 已经配置了客⼾端服务器utf8编码,但是⽆法输⼊中⽂
确保您在终端命令⾏中可以输⼊中⽂
[whb@VM-0-3-centos ~]$ env|grepLANGLANG=en_US.utf8
安装遇到秘钥过期的问题:
Failing package is: mysql-community-client-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
解决⽅案:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022