一、字符集
en_US.UTF-8:使用英语,你在美国,字符集是utf-8
zh_CN.UTF-8:使用中文,你在中国,字符集是utf-8
二、登录MYSQL:
注:MySql中添加用户,新建数据库,用户授权,删除用户,修改密码(注意每行后边都跟个英语分号符“;”表示一个命令语句结束)
# mysql -u 用户 -p密码(容易暴露密码)
# mysql -u 用户 -p (回车后输入登录密码)
三、创建用户:
创建一个名为:test 密码为:123456的用户
MariaDB [(none)]> insert into mysql.user(Host,User,Password) values("localhost","test",password("123456"));
注:“localhost"是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录需将"localhost"改为”%",表示在任何一台电脑上都可以登录,也可指定某台机器远程登录。
四、为用户授权
授权格式:grant 权限 on 数据库.* to ‘用户’@‘登录主机’ identified by ‘密码’;
1.以ROOT身份登录MySQL:
# mysql -uroot -p123456
2.首先为用户创建一个数据库(testDB):
MariaDB [(none)]> create database testDB;
3.授权test用户拥有testDB数据库的所有权限,并可以本地登录(某个数据库的所有权限):
MariaDB [(none)]> grant all privileges on testDB.* to 'test'@'localhost' identified by '123456';
4.授予test用户部分mysql数据库的权限(选择、更新),并可以本地登录
注:
‘用户名’@‘%’ 表示授予用户远程登录的权限
’用户名’@‘localhost’ 表示授予用户本地登录的权限
MariaDB [(none)]> grant select,update on mysql.* to 'test'@'localhost' identified by '123456';
5.授权test用户拥有所有数据库的select,delete,update,create,drop权限
MariaDB [(none)]> grant select,delete,update,create,drop on *.* to 'test'@"%" identified by '123456';
MariaDB [(none)]> flush privileges; #刷新系统权限表
五、修改指定用户密码
# mysql -uroot -p123456
MariaDB [(none)]> update mysql.user set password=password('000000') where User="test" and Host="localhost";
MariaDB [(none)]> flush privileges;
# mysql -utest -p000000
六、删除用户及其权限
# mysql -uroot -p123456
MariaDB [(none)]> drop user test@'%';
MariaDB [(none)]> drop user test@'localhost';
七、基本查询、切换、建表
1.列出所有数据库(show databases;)
MariaDB [(none)]> show databases;
2.切换数据库(use 数据库名;)
MariaDB [(none)]> use mysql;
3.列出所有表(show tables;)
MariaDB [mysql]> show tables;
4.显示数据表结构(describe 表名)
MariaDB [mysql]> describe user;
5.创建数据表( CREATE TABLE table_name (column_name column_type);)
MariaDB [mysql]> create table hanghang(id INT);
10.删除数据库和数据表( drop database 数据库名;drop table 数据表名;)
MariaDB [(none)]> drop database testDB;
MariaDB [mysql]> drop table hanghang;
八、修改数据库root用户密码
mysql -uroot -p
MariaDB [(none)]> use mysql;
MariaDB [(none)]> UPDATE user SET password=PASSWORD('输入新密码') WHERE user='root';
MariaDB [(none)]> FLUSH PRIVILEGES;