【日记】mysql基本操作

今天学习了mysql数据库相关操作,用的是目前最新的mysql8.0.20版本,有些语句和老版本不一样,需要注意。

用户登录DB:
mysql -u root -p

查看mysql版本
SELECT @@VERSION

创建数据库用户:
create user 'user****'@'localhost' identified by '*****password';
此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。

查看数据库用户:
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

更新数据库用户密码:
update mysql.user set authentication_string='*****' where user='user*****';

删除数据库用户:
Delete FROM mysql.user Where User='user****' and Host='localhost';

以上操作后要用下面语句刷新MySQL的系统权限相关表,否则会出现拒绝访问:
flush privileges;

授予用户访问数据库的全部权限
grant all privileges on `xxxDB`.* to 'apicaller'@'localhost' with grant option;
注意上面关键字 xxxDB的外部使用反引号`  `括起来的。

nodejs执行app.js报这个错时,
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server;
意为mysql8.0以上加密方式,Node还不支持,需要在mysql执行以下命令:
alter user 'apicaller'@'localhost' identified with mysql_native_password by '****';

查看DB
show databases;

查看表
show tables;

猜你喜欢

转载自blog.csdn.net/ttyt1217/article/details/107399122
今日推荐