赞
踩
1.安装mysql8.0
1)配置文件my.ini(8.0的my.ini文件在D:\ProgramData\MySQL\MySQL Server 8.0文件夹中。
2.安装Navicat
1)连接到mysql出现 Client does not support authentication protocol requested by server;
解决办法:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
3.eclipse通过jdbc连接到 mysql
1)获取连接失败Could not create connection to database server.
所有安装都是最新版,故JDBC连接的jar包也需最新版
更改密码和密码认证插件
在MySQL安装目录的 bin 目录下执行命令:
mysql -u root -p
这时候会提示输入密码,记住了上面第1.3步安装时的密码,填入即可登录成功,进入MySQL命令模式。
在MySQL8.0.4以前,执行
SET PASSWORD=PASSWORD('[修改的密码]');
就可以更改密码,但是MySQL8.0.4开始,这样默认是不行的。因为之前,MySQL的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”。
因为当前有很多数据库工具和链接包都不支持“caching_sha2_password”,为了方便,我暂时还是改回了“mysql_native_password”认证插件。
修改用户密码,在MySQL中执行命令:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
修改密码验证插件,同时修改密码。
如果想默认使用“mysql_native_password”插件认证,可以在配置文件中配置default_authentication_plugin项。
[mysqld]
default_authentication_plugin=mysql_native_password
示例:
C:\Program Files\MySQL\bin>mysql -u root -p Enter password: ************ Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.11 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'; Query OK, 0 rows affected (0.06 sec) mysql>
到此,安装部署就完成了。官方说测试速度MySQL8比5快两倍。
可以用 命令查看一下默认安装的数据库:
show databases;
use mysql;
show tables;
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | sys |
- +--------------------+
- 4 rows in set (0.01 sec)
-
- mysql>
看到默认初始化了mysql数据库,其中user表里面存储MySQL用户信息。我们可以看一下默认MySQL用户:
select user,host,authentication_string from mysql.user;
- mysql> select user,host,authentication_string from mysql.user;
- +------------------+-----------+-------------------------------------------+
- | user | host | authentication_string |
- +------------------+-----------+-------------------------------------------+
- | mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
- | mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
- | mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
- | root | localhost | *27C237A977F4F44D3F551F1A673BE14DFD232961 |
- +------------------+-----------+-------------------------------------------+
- 4 rows in set (0.00 sec)
-
- mysql>
管理员root的host是localhost,代表仅限localhost登录访问。如果要允许开放其他ip登录,则需要添加新的host。如果要允许所有ip访问,可以直接修改成“%”
创建用户:
CREATE USER 'xxh'@'%' IDENTIFIED WITH mysql_native_password BY 'xxh123!@#';
#(需要注意:mysql8.0加密方式修改了)
#检查用户
select user, host, plugin, authentication_string from user\G;
授权远程数据库
#授权所有权限
GRANT ALL PRIVILEGES ON *.* TO 'xxh'@'%';
#授权基本的查询修改权限,按需求设置
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'xxh'@'%';
查看用户权限
show grants for 'xxh'@'%';
示例:
- mysql> use mysql;
- Database changed
- mysql> CREATE USER 'xxh'@'%' IDENTIFIED WITH mysql_native_password BY 'xxh123!@#'; #创建用户(注意:mysql8.0加密方式修改了)
- Query OK, 0 rows affected (0.07 sec)
mysql>
查看密码加密方式:
- mysql> select user, host, plugin, authentication_string from user;
- +------------------+-----------+-----------------------+-------------------------------------------+
- | user | host | plugin | authentication_string |
- +------------------+-----------+-----------------------+-------------------------------------------+
- | xxh | % | mysql_native_password | *70FD6FB4F675E08FF785A754755B5EBA6DA62851 |
- | mysql.infoschema | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
- | mysql.session | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
- | mysql.sys | localhost | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
- | root | localhost | mysql_native_password | *27C237A977F4F44D3F551F1A673BE14DFD232961 |
- +------------------+-----------+-----------------------+-------------------------------------------+
- 5 rows in set (0.00 sec)
-
- mysql>
另外,如果需要新增账户,或者本机以外的其他人访问MySQL则还需要设置内置账户的host,具体可以参考:MySQL创建用户与授权
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。