mysql-linux归档版安装

什么是归档版安装?简单来说就是编译好的软件压缩打包版。


说明:我这里服务器之前已经装过一个不同版本的mysql,已经占用了3306端口,所以这里我用3307端口来演示,命令和官方的稍有不同,不过步骤都是差不多的


1.下载归档安装包

官方下载地址:MySQL :: Download MySQL Community Server (Archived Versions) 

 mysql-linux归档版安装_第1张图片

2.解压归档安装包 

1、先把mysql压缩包上传到linux服务器上 

2、解压到某目录下

tar -xvzf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz -C /opt/mysql/mysql2/

3、那个解压包目录名字太长了,给他换个名字,换成mysql

mv /opt/mysql/mysql2/mysql-5.7.36-linux-glibc2.12-x86_64/ /opt/mysql/mysql2/mysql 

3.创建mysql用户

其实可以不用创建mysql用户直接使用root用户,但是在公司方便不同岗位管理要专门创建一个mysql用户管理这个数据库

1、创建用户

adduser mysql3

2、修改用户密码

passwd mysql3 

 3、修改解压目录的所属用户

chown mysql3: mysql3 -R /opt/mysql/mysql2/

 -R为递归

4.创建my.cnf配置文件 

 使用mysql --help命令可以看到一段介绍

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 
 

 /opt/mysql/mysql2/mysql/bin/mysql --help

意思是默认从以下文件读取my.cnf配置文件 

在/etc/my3.cnf

[client]
#password	= your_password
port		= 3308
socket		= /opt/mysql/mysql2/mysql.sock

[mysqld]
port		= 3308
socket		= /opt/mysql/mysql2/mysql.sock
datadir = /opt/mysql/mysql2/data
basedir = /opt/mysql/mysql2/mysql
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 32M
max_allowed_packet = 100G
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 4K
read_buffer_size = 768K
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 8M
thread_cache_size = 16
tmp_table_size = 32M
default_authentication_plugin = mysql_native_password
lower_case_table_names = 1
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

explicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 3
slow_query_log=1
slow-query-log-file=/opt/mysql/mysql2/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""

innodb_data_home_dir = /opt/mysql/mysql2/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/mysql2/data
innodb_buffer_pool_size = 128M
innodb_log_file_size = 64M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 2
innodb_write_io_threads = 2

[mysqldump]
user=root
password="553057712"
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

修改my3.cnf所属用户和权限

chown mysql3:mysql3 /etc/my3.cnf

chmod 700 /etc/my3.cnf

5. 初始化数据目录

可参考官方MySQL :: MySQL 5.7 参考手册 :: 2.9.1 初始化数据目录

现在使用mysql用户操作

su mysql3 

创建数据目录 

mkdir /opt/mysql/mysql2/data

初始化数据目录

/opt/mysql/mysql2/mysql/bin/mysqld --defaults-file=/etc/my3.cnf --initialize --user=mysql3 

记住这个初始密码

mysql-linux归档版安装_第2张图片

6.启动数据库

/opt/mysql/mysql2/mysql/bin/mysqld_safe --defaults-file=/etc/my3.cnf  --user=mysql3 

7.登录

/opt/mysql/mysql2/mysql/bin/mysql -u root -p -P 3308 -S /opt/mysql/mysql2/mysql.sock

 这里注意要用-S指定mysql.sock的位置,不然-P指定端口会失效,会默认用3306

8.修改密码

 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

9.停止mysql服务

/opt/mysql/mysql2/mysql/bin/mysqladmin -uroot -p -P 3308 -S /opt/mysql/mysql2/mysql.sock shutdown

你可能感兴趣的:(数据库,linux,运维,服务器)