从mysql官网下载mysql-8.0.14-el7-x86_64.tar.gz文件
yum -y remove mariadb-libs.x86_64 //安装前请先删除或禁止其它已安装mysql相关版本
yum install -y libaio
groupadd mysql
useradd -g mysql –s /sbin/login mysql
tar mysql-8.0.14-el7-x86_64.tar.gz
mv mysql-8.0.14-el7-x86_64 /usr/local/mysql //mysql8主程序目录,默认目录位置/usr/local/mysql
mkdir /data/mysql8/data //mysql8 数据存放目录
chown -R mysql:mysql mysql8/data
chmod -R 777 /data/mysql8/log
- 创建mysql8配置文件
vim /etc/my.cnf
[mysqld] pid-file = /data/mysql8/mysqld.pid socket = /data/mysql8/mysqld.sock basedir = /usr/local/mysql datadir = /data/mysql8/data
# 日志相关 slow_query_log=ON log_error ="/data/mysql8/log/error.log" slow_query_log_file="/data/mysql8/log/blg-slow.log" long_query_time=2 log_queries_not_using_indexes = 1 log_throttle_queries_not_using_indexes = 10 expire_logs_days = 90 min_examined_row_limit = 100 log_output=TABLE,FILE general_log=1
# binlog设置 master_info_repository = TABLE relay_log_info_repository = TABLE log_bin = bin.log server-id=69
# innodb 优化设置 default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 1024M innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 2M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 innodb_buffer_pool_load_at_startup = 1 innodb_buffer_pool_dump_at_shutdown = 1 innodb_lru_scan_depth = 2000 innodb_io_capacity = 4000 innodb_io_capacity_max = 8000
# 默认参数设置 default-time-zone = '+8:00' secure-file-priv= NULL # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci default_authentication_plugin=mysql_native_password sql_mode='NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES' # # Custom config should go here #!includedir /etc/mysql/conf.d/
#----------------其它优化 (说明从上到下) # 支持符号链接,就是可以通过软连接的方式,管理其他目录的数据库,最好不要开启,当一个磁盘或分区空间不够时,可以开启该参数将数据存储到其他的磁盘或分区 symbolic-links=0 # 设置autocommit=0,则用户将一直处于某个事务中,直到执行一条commit提交或rollback语句才会结束当前事务重新开始一个新的事务(调试模式时使用) #autocommit=0 # MySQL读入缓冲区的大小 read_buffer_size = 16M # MySQL的随机读缓冲区大小、MySQL的顺序读缓冲区大小 read_rnd_buffer_size = 8M sort_buffer_size = 8M # 连接超时时间、保持时间、最大传输数据包大小 wait_timeout=2880000 interactive_timeout=2880000 max_allowed_packet=100M # 连接缓存池大小、临时表大小、临时存放位置 join_buffer_size = 128M tmp_table_size = 64M tmpdir = /tmp |
cd /data/mysql8_basedir
- 密码始化
有密码初始化
/data/mysql8/basedir/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql –initialize //执行这条命令
(无密码初始化)
( /data/mysql8/basedir/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize-insecur)
- 查看密码
cat /data/mysql8/log/err.log
2019-02-01T09:07:41.027606Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.14) initializing of server in progress as process 3816
2019-02-01T09:07:45.430058Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: GpvPoB_=/22u
2019-02-01T09:07:47.381976Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.14) initializing of server has completed
- 启动程序
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
- 登陆修root@loclhost密码和添加root@%账号
root@gxc150 mysql]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
......
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> create user 'root'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.02 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
....
- 配置环境变量
vi /etc/profile //在最后添加:
....
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
source /etc/profile //生效配置
- 关闭数据库
mysqladmin -uroot -p shutdown //密码输入刚修改的123456
- 启动数据库
mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
- 设置开机启动及快捷启动方式
cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server
vim /etc/rc.d/init.d/mysql.server //修改下面两项
...
basedir=/user/local/mysql
datadir=/data/mysql8/data
...
chmod +x /etc/rc.d/init.d/mysql.server
chkconfig --add mysql.server
service mysql.server start