一、下载
1、百度搜索mysql,进入官网(或直接进入官网https://www.mysql.com)
2、选择 downloads
3、翻到最下面,选择MySQL Community (GPL) Downloads
4、选择MySQL Community Server
5、选择archives(历史版本)
6、选择相应操作系统、版本 ,点击download 下载
二、安装
1、配置规划
压缩包存放路径: /opt/software
安装目录: /usr/local/mysql
数据文件目录: /usr/local/mysql/data
占用端口:3306
默认socket文件存放路径: /tmp/mysql.sock 客户端与服务器端通信的套接字文件
2、解压:
cd /opt/software tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
3、重命名mysql-5.7.30-linux-glibc2.12-x86_64为mysql
mv /usr/local/mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql
4、创建数据目录
mkdir /usr/local/mysql/data
5、创建mysql用户,只用于配置mysql,无登录权限
useradd -r -s /sbin/nologin mysql
6、更改/usr/local/mysql 目录权限给mysql
chown -R mysql.mysql /usr/local/mysql
7、初始化数据库
在/usr/local/mysql目录下执行初始化操作
注意:会生成一个临时密码,后面登录数据库会用到,记下来。PW-f?>wLp8wv
[root@bogon mysql]#cd /usr/local/mysql [root@bogon mysql]#bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2021-04-03T12:58:00.784162Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-04-03T12:58:00.953286Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-04-03T12:58:00.977791Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-04-03T12:58:01.034994Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3889e932-947c-11eb-85e1-000c29cabcf2. 2021-04-03T12:58:01.035793Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened. 2021-04-03T12:58:01.379465Z 0 [Warning] CA certificate ca.pem is self signed. 2021-04-03T12:58:01.454994Z 1 [Note] A temporary password is generated for root@localhost: PW-f?>wLp8wv # 临时密码
8、初始化ssl
[root@bogon mysql]# bin/mysql_ssl_rsa_setup
9、创建my.cnf配置文件
先备份原有的my.cnf
cp /etc/my.cnf /etc/my.cnf.old
修改/etc/my.cnf
vi /etc/my.cnf
[mysqld]
basedirr=/usr/local/mysql
datadir=/usr/local/data
10、mysql 启动配置
复制配置文件 mysql.server 到 /etc/init.d
cd /usr/local/mysql cp support-files/mysql.server /etc/init.d/mysqld
给所有用户赋予可执行权限
chmod a+x /etc/init.d/mysqld
设置为开机启动
chkconfig --add /etc/init.d/mysqld
chkconfig mysqld on
11、启动mysql服务
service mysqld start
mysql服务其他操作
查看mysql状态 service mysqld status
停止mysql服务 service mysqld status
重启mysql服务 service mysqld restart
12、配置环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
让配置生效
source /etc/profile
13、登录mysql
mysql -uroot -pqoge.eC#l9Wg
14、重置密码
alter user root@‘localhost‘ identified by ‘123‘;
15、重新登录
mysql -uroot -p123
16、查看数据库版本
select version;
三、重新初始化
若忘记了临时密码或意外删除了/usr/local/mysql目录等其他原因,可重新初始化。
1、停掉mysql服务
service mysqld stop
2、删除/usr/local/mysql/data 目录
rm -rf /usr/local/mysql/data
3、给目录赋权
chown -R mysql.mysql /usr/local/mysql
4、重新初始化
[root@bogon mysql]#bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
5、重新初始化ssl
[root@bogon mysql]# bin/mysql_ssl_rsa_setup