MySQL8.0安装

1.卸载系统自带的MySQL

rpm -qa|grep mysql
rpm -e --nodeps *mysql*
rpm -qa|grep mariadb
rpm -e --nodeps mariadb

2.安装MySQL8.0

 wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.15-linux-glibc2.12-x86_64.tar
tar -xvf mysql-8.0.15-linux-glibc2.12-x86_64.tar
 rm -f mysql-8.0.15-linux-glibc2.12-x86_64.tar
 xz -d mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.15-linux-glibc2.12-x86_64.tar 
mv mysql-8.0.15-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /data/mysql3306 -p

3.配置环境变量

vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin

4.创建用户组并授权目录

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
chown mysql.mysql -R /usr/local/mysql
chown mysql.mysql -R /data/mysql3306/

5.编辑配置文件

 

root@yanglin4 local]# cat /data/mysql3306/my3306.cnf 
[mysqld]
########basic settings########
server-id = 13 
port = 3306
user = mysql
character_set_server=utf8mb4
skip_name_resolve = 1
max_connections = 800
max_connect_errors = 1000
datadir = /data/mysql3306 #根据自己的配置修改
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
tmpdir = /tmp
max_allowed_packet = 16777216
#sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
interactive_timeout = 1800
wait_timeout = 1800
########log settings########
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 90
long_query_time = 2
min_examined_row_limit = 100
########replication settings########
master_info_repository = TABLE
relay_log_info_repository = TABLE
log_bin = bin.log
sync_binlog = 1
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row 
relay_log = relay.log
relay_log_recovery = 1
binlog_gtid_simple_recovery = 1
slave_skip_errors = ddl_exist_errors
########innodb settings########
innodb_buffer_pool_size = 215M #根据实际情况修改
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 2000
innodb_lock_wait_timeout = 5
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_method = O_DIRECT
innodb_undo_logs = 128
innodb_flush_neighbors = 1
innodb_log_file_size = 1G #根据实际情况修改
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1

6.数据库初始化

[root@yanglin4 data]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3306/
2020-07-05T12:16:03.242787Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-07-05T12:16:03.242928Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.15) initializing of server in progress as process 15293
2020-07-05T12:16:07.025093Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 8ya4xi1d8p>Y
2020-07-05T12:16:09.070255Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.15) initializing of server has completed

7.配置mysql自启动

[root@yanglin4 data]# vim /usr/lib/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:msyqld(8)
Documentation=http://dev.msyql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql3306/my3306.cnf
LimitNOFILE=65535
LimitNPROC=65535

8.配置systemctl启动和停止

systemctl daemon-reload
systemctl stop mysqld
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld

9.启动并初始化密码

mysqld_safe --defaults-file=/data/mysql3306/my3306.cnf &

mysql> alter user root@'localhost' identified with mysql_native_password by '123456';

 

posted @ 2020-07-05 12:49  从此重新定义啦  阅读(393)  评论(0编辑  收藏  举报