将root扩展权限(mysql8)
update user set host='%' where user='root';
flush privileges;
运行上面两句话之后就可以通过root账户远程登陆。
=======================================================================
数据库版本:mysql 5.8.0.15
查看原有数据库中的用户
mysql的用户信息主要存放在mysql数据库中的user表中
select host,user from user;
输出
查看某个用户的权限
show grants for 'meiqi4'@'%';
输出
添加远程用户
create user 'meiqi4'@'%' identified by 'Ali_我的台式机的密码'
查看一下现在的user表
为新用户创建数据库
重新登陆新建的用户,可以看到新建的用户下面只有一个数据库
创建数据库
创建数据库的工作要在root账号下操作,然后给新用户(meiqi4)权限。
首先以root身份登陆并创建数据库
create database nbiot;
在数据库中创建表table1_shijian_jiedian;
切换数据库
use nbiot;
在数据库中建表
CREATE TABLE IF NOT EXISTS `meiqi4`(
`DiZhiMa` VARCHAR(20) NOT NULL,
`GongNengMa` VARCHAR(20) NOT NULL,
`ZiJieShu` VARCHAR(20) NOT NULL,
`JiQiMa` VARCHAR(20) NOT NULL,
`QiTiLeiXing` VARCHAR(20) NOT NULL,
`DanWei` VARCHAR(20) NOT NULL,
`TangCeQiZhuangTai` VARCHAR(20) NOT NULL,
`QiTiNongDu` VARCHAR(20) NOT NULL,
`DiXian` VARCHAR(20) NOT NULL,
`GaoXian` VARCHAR(20) NOT NULL,
`DianLiang` VARCHAR(20) NOT NULL,
`WenDuZhengShu` VARCHAR(20) NOT NULL,
`WenDuXiaoShu` VARCHAR(20) NOT NULL,
`Date` datetime NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
为新用户授权
因为是远程用户,为了安全性考虑,只给他查询的权限
GRANT select ON nbiot.meiqi4 TO 'meiqi4'@'%';
至此,一个可用于远程访问的用户已经实现,并且将一个表授权给这个远程用户了。
用C#连接时的错误
Authentication method 'caching_sha2_password' not supported by any of the available plugins.
引起这个问题的原因时mysql第八个版本中将密码的加密方式个更改了,用下面的命令可以看出来现在的加密形式不是原先的mysql。。。,而是ca。。。。
select host, user, authentication_string, plugin from user;
解决方法如下
alter user 'meiqi4'@'%' identified by 'Ali_台式机密码' password expire never;
alter user 'meiqi4'@'%' identified with mysql_native_password by 'Ali_台式机密码';
flush privileges;
alter user 'meiqi4'@'%' identified by 'Ali_台式机密码';
然后修改/etc/my.cnf
配置文件
1 # For advice on how to change settings please see
2 # http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
3
4 [mysqld]
5 #
6 # Remove leading # and set to the amount of RAM for the most important data
7 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
8 # innodb_buffer_pool_size = 128M
9 #
10 # Remove the leading "# " to disable binary logging
11 # Binary logging captures changes between backups and is enabled by
12 # default. It's default setting is log_bin=binlog
13 # disable_log_bin
14 #
15 # Remove leading # to set options mainly useful for reporting servers.
16 # The server defaults are faster for transactions and fast SELECTs.
17 # Adjust sizes as needed, experiment to find the optimal values.
18 # join_buffer_size = 128M
19 # sort_buffer_size = 2M
20 # read_rnd_buffer_size = 2M
21 #
22 # Remove leading # to revert to previous value for default_authentication_plugin,
23 # this will increase compatibility with older clients. For background, see:
24 # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
25 default-authentication-plugin=mysql_native_password#这行原先是注释的
26
27 datadir=/var/lib/mysql
28 socket=/var/lib/mysql/mysql.sock
29
30 log-error=/var/log/mysqld.log
31 pid-file=/var/run/mysqld/mysqld.pid
执行命令,重启服务
service mysqld restart
然后C#就能正常访问远程数据库了
参考链接
https://www.cnblogs.com/xujishou/p/6306765.html
《MySQL5.7 添加用户、删除用户与授权》
https://www.cnblogs.com/wanghetao/p/3806888.html
MySQL添加用户、删除用户与授权
https://blog.csdn.net/u011583336/article/details/80999043
mysql 报错Authentication method ‘caching_sha2_password’ is not supported.