1、创建数据库
CREATE DATABASE dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
2、创建用户
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
3、授权数据库
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';
刷新权限:FLUSH PRIVILEGES;
4、修改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
--------------------------------------------
mysql -u username -p
常用命令:
show databases;
use database_name;
show tables;
desc table_name;
truncate table xxx; // 清空表数据,清空后自增字段从初始值开始,delete删除或清空数据,自增字段不会恢复初始值
alter table xxx add ... //增加字段
alter table xxx modify [column_name ...] //修改字段
alter table xxx change [column_name] [column_name ...] //修改字段,可修改字段名
--------------------------------------------
mac 启动mysql : /usr/local/mysql/support-files/mysql.server start
网友评论