目录
下载
上传解压
安装
编辑my.cnf配置文件
启动数据库
修改初始密码,授权远程登录
常见问题
下载
访问以下地址下载对应操作系统下所需的版本
https://downloads.mysql.com/archives/community/
上传解压
使用ftp或者rz命令上传压缩包到服务器并执行 tar -xvf 压缩包文件 进行解压(本例已5.7.39)为例,
[root@i-DE074A35 soft]# tar -xvf mysql-5.7.39-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.39-1.el7.x86_64.rpm
mysql-community-common-5.7.39-1.el7.x86_64.rpm
mysql-community-devel-5.7.39-1.el7.x86_64.rpm
mysql-community-embedded-5.7.39-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.39-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.39-1.el7.x86_64.rpm
mysql-community-libs-5.7.39-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.39-1.el7.x86_64.rpm
mysql-community-server-5.7.39-1.el7.x86_64.rpm
mysql-community-test-5.7.39-1.el7.x86_64.rpm
安装
按续安装如下rpm包(并非解压出来的所有包都需要安装)
[root@i-DE074A35 soft]# rpm -ivh mysql-community-common-5.7.39-1.el7.x86_64.rpm
[root@i-DE074A35 soft]# rpm -ivh mysql-community-libs-5.7.39-1.el7.x86_64.rpm
[root@i-DE074A35 soft]# rpm -ivh mysql-community-devel-5.7.39-1.el7.x86_64.rpm
[root@i-DE074A35 soft]# rpm -ivh mysql-community-client-5.7.39-1.el7.x86_64.rpm
[root@i-DE074A35 soft]# rpm -ivh mysql-community-server-5.7.39-1.el7.x86_64.rpm
编辑my.cnf配置文件
vi /etc/my.cnf 添加修改以下内容
[mysqld]
datadir=/mysql/data
socket=/mysql/mysqld.sock
log-error=/mysql/mysqld.log
pid-file=/mysql/mysqld.pid
[mysql]
socket=/mysql/mysql.sock
[client]
socket=/mysql/mysql.sock
[mysqldump]
socket=/mysql/mysql.sock
[mysqladmin]
socket=/mysql/mysql.sock
启动数据库
[root@i-DE074A35 soft]# systemctl start mysqld
修改初始密码,授权远程登录
查看初始密码
cat /mysql/mysqld.log | grep password,如下查询结果中‘=biHMs1iw/x)’就是初始密码
[root@i-DE074A35 mysql]# cat /app/mysql/mysqld.log |grep password
2022-12-28T08:36:39.605019Z 1 [Note] A temporary password is generated for root@localhost: =biHMs1iw/x)
2022-12-28T08:43:33.769392Z 0 [Note] Shutting down plugin 'validate_password'
2022-12-28T08:43:34.988421Z 0 [Note] Shutting down plugin 'sha256_password'
2022-12-28T08:43:34.988425Z 0 [Note] Shutting down plugin 'mysql_native_password'
2022-12-28T08:46:31.609019Z 0 [Note] Shutting down plugin 'validate_password'
2022-12-28T08:46:33.226433Z 0 [Note] Shutting down plugin 'sha256_password'
2022-12-28T08:46:33.226437Z 0 [Note] Shutting down plugin 'mysql_native_password'
登录数据库修改密码
[root@i-DE074A35 soft]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.39
Copyright (c) 2000, 2022, 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> alter user 'root'@'localhost' identified by 'Mysql_2022!'
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'Mysql_2022!' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
常见问题
问题一:登录或使用中提示如下报错Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@i-DE074A35 soft]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
查看上述步骤中【编辑my.cnf配置文件】添加socket的位置指定内容,重启数据库即可