linux下安装mysql8.0(二进制方式)
环境
OS:Centos 7
1.下载安装介质
官网下载
我这里下载的是8.0.17
mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
2.创建mysql用户和用户组
#groupadd mysql
#useradd -g mysql mysql
#passwd mysql
3.下载解压安装
[root@localhost soft]# tar -xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
[root@localhost soft]# mv mysql-8.0.17-linux-glibc2.12-x86_64 /opt/mysql8
4.创建相应的目录
[root@localhost mysql8]# mkdir data ##数据文件目录
[root@localhost mysql8]# mkdir conf ## 配置文件目录
[root@localhost mysql8]# mkdir redolog ##redo日志文件
[root@localhost mysql8]# mkdir -p mysqllog/relaylog ##主从环境relaylog
[root@localhost mysql8]# mkdir -p mysqllog/logfile ##错误日志文件
[root@localhost mysql8]# mkdir -p mysqllog/binlog ##binlog文件
[root@localhost mysql8]# mkdir ibdata ##ibdata文件
5.初始化数据库
root账户下
[root@localhost bin]# ./mysqld --initialize --lower-case-table-names=1 --user=mysql --basedir=/opt/mysql8 --datadir=/opt/mysql8/data
2019-09-05T08:25:17.210466Z 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.
2019-09-05T08:25:17.210613Z 0 [System] [MY-013169] [Server] /opt/mha/mysql8/bin/mysqld (mysqld 8.0.17) initializing of server in progress as process 25951
2019-09-05T08:25:38.288278Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: vew-DWj=q4r<
2019-09-05T08:25:49.555673Z 0 [System] [MY-013170] [Server] /opt/mha/mysql8/bin/mysqld (mysqld 8.0.17) initializing of server has complete
这里初始化密码为vew-DWj=q4r<
若不想要初始化密码,不需要密码的话可以采用如下方法初始化话
./mysqld --initialize-insecure --user=mysql --basedir=/opt/mha/mysql8 --datadir=/opt/mha/mysql8/data
6.配置文件
[mysqld]
port=13306
server-id=3
basedir=/opt/mysql8
datadir=/opt/mysql8/data
socket=/opt/mysql8/mysql.sock
max_connections = 10000
character_set_server=utf8mb4
collation-server=utf8mb4_general_ci
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'
interactive_timeout=86400
wait_timeout=86400
skip-external-locking
key_buffer_size= 128M
max_allowed_packet=32M
##query_cache_size=32M
read_buffer_size=2M
sort_buffer_size=1M
join_buffer_size= 128M
innodb_file_per_table= 1
innodb_open_files= 5000
innodb_buffer_pool_size= 10G
innodb_write_io_threads= 16
innodb_read_io_threads= 16
innodb_thread_concurrency = 0
innodb_purge_threads= 1
innodb_flush_log_at_trx_commit= 2
innodb_log_buffer_size=16M
innodb_log_file_size=512M
innodb_log_files_in_group= 5
innodb_max_dirty_pages_pct= 90
innodb_lock_wait_timeout= 120
bulk_insert_buffer_size= 64M
myisam_sort_buffer_size=64M
myisam_max_sort_file_size= 10G
myisam_repair_threads= 1
log_bin_trust_function_creators=1
event_scheduler=1
max_binlog_size=100M
binlog_format=row
log-bin=/opt/mysql8/mysqllog/binlog/binlog.bin
slow_query_log=on
slow_query_log_file=/opt/mysql8/mysqllog/logfile/slow-query.log
long_query_time=1
log_queries_not_using_indexes=on
log-error=/opt/mysql8/mysqllog/logfile/mysql-err.log
binlog_cache_size=4MB
skip-host-cache
skip-name-resolve
##已经没有该参数了expire_logs_days=15
##3*24*60*60=259200 3天
binlog_expire_logs_seconds=259200
##skip_replica_start
skip-slave-start
relay-log-index=/opt/mysql8/mysqllog/relaylog/slave-relay-bin.index
relay-log=/opt/mysql8/mysqllog/relaylog/relaylog-binlog
replicate-ignore-db=information_schema,performance_schema,sys
##replica_net_timeout=60
slave_net_timeout=60
##language=/opt/mysql8/share/english
early-plugin-load=""
explicit_defaults_for_timestamp=true
##log_replica_updates=1
log_slave_updates=1
gtid_mode=ON
enforce_gtid_consistency = ON
lower_case_table_names=1
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO'
secure_file_priv=/opt/mysql8/secure_file
default_authentication_plugin=mysql_native_password
[client]
port = 13306
default-character-set = utf8mb4
[mysqldump]
quick
max_allowed_packet = 32M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
7.修改目录权限
[root@localhost mha]# cd /opt
[root@localhost opt]# chown -R mysql:mysql ./mysql8
8.启动
(在mysql用户下执行)
[mysql@localhost bin]$ /opt/mysql8/bin/mysqld_safe --defaults-file=/opt/mysql8/conf/my.cnf --user=mysql &
9.登陆数据库修改相应用户密码
[mysql@localhost bin]$ ./mysql -h localhost -uroot -P13306 -S /opt/mysql8/mysql.sock -p
mysql> select version();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
提示修改密码
alter user 'root'@'localhost' identified by 'mysql';
flush privileges;
10.重新登录
[mysql@localhost bin]$ ./mysql -h localhost -uroot -P13306 -S /opt/mysql8/mysql.sock -pmysql
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.17 |
+-----------+
1 row in set (0.00 sec)
11.创建开发用户
在mysql8.0创建用户和授权和之前不太一样了,其实严格上来讲,也不能说是不一样, 只能说是更严格, mysql8.0需要先创建用户(创建用户时要带@并指定地址, 则grant授权时的地址就是这个@后面指定的!, 否则grant授权就会报错!)和设置密码,然后才能授权。
create user 'hxl'@'%' identified by 'mysql';
grant all privileges on *.* to 'hxl'@'%' with grant option;
采用5.7之前的办法创建用户会报错
mysql> grant all privileges on *.* to 'hxl01'@'%' identified by 'mysql';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'mysql'' at line 1