mysql常用功能及语句(后续继续补充)

2019-03-14  本文已影响0人  旅行者xy

创建数据库及用户

CREATE SCHEMA database_name DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ;

CREATE USER admin@localhost IDENTIFIED BY '123';
admin为用户名,123位密码,localhost为允许登录的IP地址,设为'%'表示允许所有IP地址登录

GRANT privileges ON databasename.tablename TO 'username'@'host'

说明: privileges - 用户的操作权限,如SELECT , INSERT , UPDATE 等。如果要授予所的权限则使用 ALL;
databasename - 数据库名,tablename-表名,如果要授予该用户对所有数据库和表的相应操作权限则可用表示, 如.*
例如:

GRANT INSERT,DELETE,UPDATE,SELECT ON test.user TO 'admin'@'localhost';
flush privileges;

SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword')
如果是当前登陆用户
SET PASSWORD = PASSWORD("newpassword");
例如:
SET PASSWORD FOR 'admin'@'%' = PASSWORD("123456");
update mysql.user set password=password('新密码') where User="admin" and Host="localhost";

删除数据操作

update table_name set field_name = replace(field_name, '_', '-');

delete from user where host='localhost' and user='root';

上一篇下一篇

猜你喜欢

热点阅读