首先使用root賬號登錄mysql,
mysql -u root -p;
show databases;查看自己的數(shù)據(jù)庫
mysql> show databases;
+----------------------------+
| Database |
+----------------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
| user_center |
| user_center_bak_20191225 |
| user_center_bak_2019122501 |
| user_center_bak_20200118 |
| weapp |
| yshop |
+----------------------------+
11 rows in set (0.01 sec)
創(chuàng)建用戶
‘%’ - 所有情況都能訪問
‘localhost’ - 本機才能訪問
’111.222.33.44‘ - 指定 ip 才能訪問
刪除用戶:
delete from mysql.user where user='用戶名';
//低版本數(shù)據(jù)庫
create user '用戶民'@'%' identified by '密碼';
//高版本數(shù)據(jù)庫
create user '用戶名'@'%' identified with mysql_native_password by '密碼';
修改密碼
alter user '用戶名'@'%' identified by '密碼';
創(chuàng)建數(shù)據(jù)庫
//創(chuàng)建數(shù)據(jù)庫
create database [database name];
//查看數(shù)據(jù)庫
show databases;
//刪除數(shù)據(jù)庫
drop database [database name];
給指定用戶授權(quán)數(shù)據(jù)庫
//指定數(shù)據(jù)庫 all全部權(quán)限可選all select,delete,update,create,drop
grant all privileges on 想授權(quán)的數(shù)據(jù)庫.* to '用戶名'@'%';
//全部數(shù)據(jù)庫
grant all privileges on *.* to '用戶名'@'%';
刷新權(quán)限
flush privileges;