MySQL8.0安装官方文档:
https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
安装前注意:
MySQL8.0和MySQL5.7和之前的版本还是有区别的,第一点就是在安装MySQL的时候 密码认证方式:默认的密码加密方式是:caching_sha2_password,而现在很多客户端工具还不支持这种加密认证方式,可以在配置文件中加入:default_authentication_plugin=mysql_native_password;这样就和MySQL5.7和之前的版本一样了。
1、下载二进制软件包:
mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
2、添加MySQL用户和组:
[[email protected]ost ~]# userdel mysql (因为是新系统,所以就把现有的MySQL用户给删除了) [[email protected] ~]# groupadd mysql [[email protected] ~]# useradd -g mysql mysql [[email protected] ~]# passwd mysql (MySQL密码要设置的复杂一点,或者在创建用户的时候设置不让登陆系统)
3、创建安装MySQL目标,并解压软件到指定目录
[[email protected] ~]# mkdir -p /mysql/data [[email protected] ~]# chown -R mysql.mysql /mysql [[email protected] ~]# tar zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz -C /mysql [[email protected] ~]# cd /mysql [[email protected] ~]# mv mysql-8.0.11-linux-glibc2.12-x86_64 / mysql [[email protected] ~]# chown -R mysql.mysql /mysql
4、初始化数据库
[[email protected] ~]# su - mysql
[[email protected] ~]$ vim /mysql/my.cnf
[client] socket=/mysql/data/mysql.sock [mysqld] server-id=142 port = 3306 basedir=/mysql/mysql datadir=/mysql/data socket=/mysql/data/mysql.sock log-error=/mysql/data/mysqld.log pid-file=/mysql/data/mysqld.pid log-bin=/mysql/data/binlog slow_query_log_file = /mysql/data/slow.log log_slave_updates expire_logs_days=7 binlog_format=ROW #default_authentication_plugin=mysql_native_password ---修改密码加密方式。(看文中最后的解释) gtid-mode = on enforce-gtid-consistency = 1 skip_slave_start=1 innodb_buffer_pool_size = 1000M innodb_buffer_pool_instances = 2 innodb_log_file_size = 100M innodb_log_files_in_group = 3 innodb_log_buffer_size = 24M innodb_flush_log_at_trx_commit = 1 innodb_file_per_table = 1 innodb_flush_method = O_DIRECT innodb_io_capacity = 200 innodb_io_capacity_max = 600 innodb_thread_concurrency = 0 innodb_autoinc_lock_mode = 2 innodb_lock_wait_timeout = 60 innodb_read_io_threads = 4 innodb_write_io_threads = 4 innodb_max_dirty_pages_pct = 80 innodb_autoextend_increment = 512 innodb_checksum_algorithm = NONE max_connect_errors = 1000 max_connections = 500 connect_timeout = 300 wait_timeout = 86400 interactive_timeout = 86400
[[email protected] mysql]$ /mysql/mysql/bin/mysqld --defaults-file=/mysql/my.cnf --user=mysql --basedir=/mysql/mysql/ --datadir=/mysql/data/ --initialize
其中,root的默认密码在:/mysql/data/mysqld.log 日志中,打开查看即可
5、启动MySQL
[[email protected] mysql]# /mysql/mysql/bin/mysqld_safe --defaults-file=/mysql/my.cnf --user=mysql & [[email protected] mysql]# /mysql/mysql/bin/mysql -uroot -p -S /mysql/data/mysql.sock mysql> set password='123456'; mysql> flush privileges; mysql> \s -------------- /mysql/mysql/bin/mysql Ver 8.0.11 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL) Connection id: 11 Current database: Current user: [email protected] SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 8.0.11 MySQL Community Server - GPL Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8mb4 Conn. characterset: utf8mb4 UNIX socket: /mysql/data/mysql.sock Uptime: 10 min 31 sec Threads: 2 Questions: 10 Slow queries: 0 Opens: 124 Flush tables: 2 Open tables: 100 Queries per second avg: 0.015 --------------
(注意:这里启动数据库一定要用MySQL8.0安装包自带的客户端才可以登录,即要使用MySQL8.0安装包的命令进行登录数据库,要不然会报错,如:
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded:)
注意:
在mysql8.0下,默认变成了default_authentication_plugin=caching_sha2_password,包括你刚初始化的root用户也是这个认证加密方式,这样的结果是让你除非用新的协议驱动,例如必须用8.0自带的mysql客户端才行,不然就连接不上数据库.
在mysql5.7环境里,虽然可以设置default_authentication_plugin来改变认证加密方式,但是一般人不会去设置.所以默认使用的认证加密方式是mysql_native_password
解决方法:
①:在初始化的时候在配置文件中加入,如下,mysql_native_password 这种认证方法就会很多客户端的认证加密方式一样。
vim my.cnf
[mysqld]
default_authentication_plugin=mysql_native_password
②:使用命令行模式更改用户的密码加密认证方式:
mysql> select Host,User,plugin,authentication_string from mysql.user; --看下面的root用户的认证方式和其他用户都是不一样的, +-----------+------------------+-----------------------+------------------------------------------------------------------------+ | Host | User | plugin | authentication_string | +-----------+------------------+-----------------------+------------------------------------------------------------------------+ | localhost | mysql.infoschema | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | localhost | mysql.session | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | localhost | mysql.sys | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | localhost | root | caching_sha2_password | $A$005$T?yK{e`l{mrnZd|0iETvMwJ197qvnDXttfzdZX98q6xvFBwXuWd3ioPfnV7 | +-----------+------------------+-----------------------+------------------------------------------------------------------------+ 4 rows in set (0.00 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; ---在修改密码的时候指定密码加密认证方式 Query OK, 0 rows affected (0.11 sec) mysql> select Host,User,plugin,authentication_string from mysql.user; ---再次查看所有用户都一样了,和5.7版本一样 +-----------+------------------+-----------------------+-------------------------------------------+ | Host | User | plugin | authentication_string | +-----------+------------------+-----------------------+-------------------------------------------+ | localhost | mysql.infoschema | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | localhost | mysql.session | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | localhost | mysql.sys | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | localhost | root | mysql_native_password | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +-----------+------------------+-----------------------+-------------------------------------------+ 4 rows in set (0.00 sec)
另外,在MySQL8.0授权和创建用户更加严格了,在MySQL5.7可以使用命令如下:
MySQL [(none)]> grant all privileges on *.* to 'test_user'@'192.168.2.%' identified by '123123'; ----MySQL5.7创建用户授权的方法,报错了,
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 '123123'' at line 1
在MySQL8.0中必须先创建用户再授权:
MySQL > create user 'test_user'@'%' identified by '123456'; --先创建用户
Query OK, 0 rows affected (0.03 sec)
MySQL > grant all privileges on *.* to 'test_user'@'%' with grant option; --再授权
Query OK, 0 rows affected (0.05 sec)
MySQL8.0的版本还是有很多变化的,技术在不断更新所以要努力学习!
原文地址:http://blog.51cto.com/fengfeng688/2141752