1、下载mysql
https://downloads.mysql.com/archives/community/
2、创建用户组
groupadd mysql
3、创建用户
useradd -r -g mysql5736 mysql5736
4、解压文件
tar zxvf mysql-5.7.39-linux-glibc2.12-x86_64.tar.gz
5、重命名
mv mysql-5.7.39-linux-glibc2.12-x86_64 ./mysql5739
6、关联用户到用户组
chown -R mysql:mysql /usr/local/mysql5739
chown -R mysql:mysql /usr/local/mysql5739/data
更改mysql安装文件夹mysql/的权限
chmod -R 755 /usr/local/mysql3308
7、创建my.cnf 在mysql3308目录下
[client]
port = 5739
socket = /usr/local/mysql5739/data/mysql.sock
[mysqld]
port = 5739
# server-id表示单个结点的id,这里由于只有一个结点,所以可以把id随机指定为一个数,这里将id设置成1。若集群中有多个结点,则id不能相同
server-id=1
# log-bin日志文件的名字为mysql-bin,以及其存储路径
log-bin=/usr/local/mysql5739/log-bin/mysql-bin
datadir = /usr/local/mysql5739/data
basedir = /usr/local/mysql5739
socket = /usr/local/mysql5739/data/mysql.sock
log-error = /usr/local/mysql5739/logs/error.log
pid-file = /usr/local/mysql5739/data/mysqld.pid
max_connections = 2000
symbolic-links=0
tmp_table_size = 256M
max_heap_table_size = 256M
group_concat_max_len=102400
max_connections = 2000
character-set-server = utf8
interactive_timeout = 1800
wait_timeout = 2400
max_allowed_packet = 32M
binlog_cache_size = 8M
sort_buffer_size = 4M
read_buffer_size = 256M
join_buffer_size = 256M
tmp_table_size = 256M
max_heap_table_size = 256M
max_length_for_sort_data = 8096
#innodb
innodb_file_per_table = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_flush_method = O_DIRECT
innodb_autoinc_lock_mode = 2
innodb_read_io_threads = 16
innodb_write_io_threads = 16
innodb_buffer_pool_size = 4G
innodb_temp_data_file_path=ibtmp1:12M:autoextend:max:5G
8、在mysql3308 下创建data、logs、log-bin
9、初始化mysql
./bin/mysqld --defaults-file=/usr/local/mysql5739/my.cnf --basedir=/usr/local/mysql5739/ --datadir=/usr/local/mysql5739/data --user=mysql --initialize
初始密码在my.cnf 配置的log-error 日志里面
10、启动
./bin/mysqld_safe --defaults-file=/usr/local/mysql5739/my.cnf &
11、登录
/mysql -h 127.0.0.1 -uroot -P5739 -p
12、修改密码
set password=password('新密码');
停止mysql
./mysqladmin -uroot -p -S /usr/local/mysql5739/data/mysql.sock shutdown
备份
./mysqldump -h10.128.85.137 -p5739 -u账号 -p密码 数据库名称 表名>/tmp/表名.sql
记一个错误
测试环境初始化数据库命令可以正常进行
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql5739 --datadir=/usr/local/mysql5739/data
但是正式环境初始化失败,没有日志输出,data文件初始化也不对,只有4个文件
ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1
后来变更了初始化命令的位置,就可以正常初始化了
./bin/mysqld --defaults-file=/usr/local/mysql5739/my.cnf --basedir=/usr/local/mysql5739/ --datadir=/usr/local/mysql5739/data --user=mysql --initialize