use mysql;
select user, host, authentication_string, plugin from user;
update user set host='%' where user='root';
update user set plugin='mysql_native_password' where user='root';
# mysql5.7之前修改密码
update user set password=password("root") where user="root";
# mysql5.7之后(包括5.7)修改密码方法一
update user set authentication_string=password('root') where user='root';
# mysql5.7之后(包括5.7)修改密码方法二
alter user 'root'@'localhost' identified by 'root';
alter user USER() identified by 'root';
alter user 'root'@'%' identified by 'root';
# mysql5.7之后(包括5.7)修改密码方法三
alter user 'root'@'%' identified with mysql_native_password by 'root';
# 添加用户
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
flush privileges;
mysql使用
授予所有权限
grant all privileges on databasename.tablename to 'user'@'host';
FLUSH PRIVILEGES;
收回所有权限
revoke all privileges on databasename.tablename from 'user'@'host';
FLUSH PRIVILEGES;
授予查询权限
grant select on databasename.tablename to 'user'@'host';
FLUSH PRIVILEGES;
收回查询权限
revoke select on databasename.tablename from 'user'@'host';
FLUSH PRIVILEGES;
建立新用户
create user user@host identified by 'password';
FLUSH PRIVILEGES;
删除用户
drop user 'user'@'host';
创建数据库并指定字符集
CREATE DATABASE IF NOT EXISTS databasename DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
create database dbName default character set utf8mb4 collate utf8mb4_unicode_ci;
删除数据库
drop database databasename;
创建表
use databasename;
create table tbl_emp(
emp_id int(11) auto_increment not null primary key,
emp_name varchar(255) not null,
gender char(1),
email varchar(255),
d_id int(11)
);
create table tbl_dept(
dept_id int(11) auto_increment not null primary key,
dept_name varchar(255) not null,
foreign key(dept_id) references tbl_emp(d_id)
);
删除表
use databasename;
drop table tablename;
update db1.table1 a inner join db2.table2 b on a.col1=b.col2 set a.col3=''
设置root密码未设置密码:mysql -u root若已经设置:mysql -u root -puse mysql;UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';FLUSH PRIVILEGES;设置远程登陆用户use mysql;insert into user(Host,Us