1、下载tar包,这里使用wget从官网下载sudo wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
2、将mysql安装到/home/install下# 解压
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /home/install
# 重命名mv /home/install/mysql-5.7.22-linux-glibc2.12-x86_64 /home/install/mysql
3、新建data目录mkdir /home/install/mysql/data
4、新建mysql用户、mysql用户组
# mysql用户组groupadd mysql
# mysql用户useradd mysql -g mysql
5、将/home/install/mysql的所有者及所属组改为mysqlchown -R mysql.mysql /home/install/mysql
6、更改mysql安装文件夹mysql/的权限chmod -R 755 /home/install/mysql
7、安装依赖软件
# 执行以下命令安装numactl:yum -y install numactl.x86_64
#安装libaio#yum install libaio
# 完成后继续执行初始化mysql命令:cd /home/install/mysql/bin/
./mysqld --user=mysql --basedir=/home/install/mysql/ --datadir=/home/install/mysql/data --initialize
此时,会生成如下一段文字:[Note] A temporary password is generated for root@localhost: o*s#gqh)F4Ck
上面生成信息中的root@localhost:后面的内容是一个临时密码(每个人执行命令时生成的临时密码不一样),请先保存此密码,后面会使用这个密码。
8、配置
# 编辑/etc/my.cnf,将下面内容完全替换原有内容[client]
no-beep
socket =/home/install/mysql/mysql.sock
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
basedir=/home/install/mysql
datadir=/home/install/mysql/data
port=3306
pid-file=/home/install/mysql/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /home/install/mysql/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /home/install/mysql/data
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
注意:上面配置文件中的log-error和pid-file中的文件必须存在,不存在需要创建这两个文件,并且给这两个文件授予读写权限:chomod -R 777 mysqld.log(两个文件都需要给与777授权,否则后续启动mysql会报错)
#修改Mysql配置文件vi /home/install/mysql/support-files/mysql.server
将其中的“basedir”的等号后面加上你的Mysql路径:basedir=/home/install/mysql
datadir=
9、开启服务
#检查/etc/init.d/下是否有mysqld文件,没有的话执行下方命令复制到此处,将mysql加入服务,存在则跳过次步骤cp /home/install/mysql/.support-files/mysql.server /etc/init.d/mysqld
注意:如果上面文件不存在,且不执行上述命令,后续启动的时候可能会报如下错误:/etc/init.d/mysqld: No such file or directory
# 开机自启chkconfig mysql on
# 开启service mysql start
10、设置密码
# 登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)/home/install/mysql/bin/mysql -u root -p
# 操作mysql数据库
>>use mysql;
# 修改密码>>update user set authentication_string=password('你的密码') where user='root';
>>flush privileges;
>>exit;
11、将/etc/my.cnf中的skip-grant-tables删除
12、登录再次设置密码(不知道为啥如果不再次设置密码就操作不了数据库了)/home/install/mysql/bin/mysql -u root -p
>>ALTER USER 'root'@'localhost' IDENTIFIED BY '修改后的密码';
>>exit;
13、允许远程连接/home/install/mysql/bin/mysql -u root -p
>>use mysql;
>>update user set host='%' where user = 'root';
>>flush privileges;
>>eixt;
14、添加快捷方式ln -s /home/install/mysql/bin/mysql /usr/bin