1:下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar
2:解压下载的mysql压缩包
解压mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar
tar -xf mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar
解压后生成3个压缩文件
继续解压mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar.xz
tar -xf mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar.xz
3:安装mysql
1:因为要安装多个mysql,所以要修改文件名称,修改文件所属的账户和权限
修改文件名称
mv mysql-8.0.33-linux-glibc2.17-x86_64-minimal mysql3310
mv mysql-8.0.33-linux-glibc2.17-x86_64-minimal mysql3309
修改文件所属的账户
先添加mysql用户组:groupadd mysql
在mysql用户组下添加mysql用户:useradd mysql -g mysql
修改文件所属账户:chown -R mysql:mysql /usr/local/soft/mysql*
修改文件的权限:chmod -R 755 usr/local/soft/mysql*
2:创建日志文件和存放数据文件,以及mysql的配置文件my.cnf
在mysql3310和mysql3309下创建
mkdir data
mkdir log
vim my.cnf 这个文件的权限记得修改一下,因为它如果权限过大,在启动还是初始化的时候不行
3:修改my.cnf配置
[mysqld]
bind-address=0.0.0.0
port=3310
user=mysql
basedir=/usr/local/soft/mysql3310
datadir=/usr/local/soft/mysql3310/data
socket=/usr/local/soft/mysql3310/mysql3310.sock
log-error=/usr/local/soft/mysql3310/log/mysql.err
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
general_log=1
general_log_file=/usr/local/soft/mysql3306/log/mysql_3306.log
lower_case_table_names=1
# 设置日期时间列的默认格式
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
default_time_zone = '+8:00'
这5个表黄的也重要
mysqlx_port=33310
mysqlx_bind_address=0.0.0.0
mysqlx_socket=/usr/local/soft/mysql3310/mysql3310.sock
这三个标红的文件特别重要,这个是配置套字节,如果没有配置的话在连接的时候,会说找不到套字节
[mysqld_safe]
user=mysql
log-error=/usr/local/soft/mysql3310/log/mysqld3310.log
pid-file=/usr/local/soft/mysql3310/mysqld3310.pid
socket=/usr/local/soft/mysql3310/mysql3310.sock
mysqlx_port=33310
mysqlx_bind_address=0.0.0.0
mysqlx_socket=/usr/local/soft/mysql3310/mysql3310.sock
[client]
socket=/usr/local/soft/mysql3310/mysql3310.sock
[mysqldump]
socket=/usr/local/soft/mysql3310/mysql3310.sock
[mysqladmin]
socket=/usr/local/soft/mysql3310/mysql3310.sock
4:初始化mysql
./mysqld --defaults-file=/usr/local/soft/mysql3309/my.cnf --initialize --basedir=/usr/local/soft/mysql3309 --datadir=/usr/local/soft/mysql3309/data/
初始化完成后,会在data文件生成相关的信息,如果觉得不对的话,可以把date里面的内容删除掉,重新初始化。
初始化的话,会在配置的日志文件里生成root账户的密码,用于第一次登录
5:启动mysql
1:用mysqld_safe的方式启动
/usr/local/soft/mysql3310/bin/mysqld_safe --defaults-file=/usr/local/soft/mysql3310/my.cnf &
2:或者用mysqld直接启动
/usr/local/soft/mysql3310/bin/mysqld --defaults-file=/usr/local/soft/mysql3310/my.cnf -D
6:登录:
/usr/local/soft/mysql3310/bin/mysql -uroot -p -h 127.0.0.1 --port=3310