MySQL、Mariadb数据库基本操作

一、字符集

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;

在这里插入图片描述

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zcoder`Blog

嘻嘻~谢谢打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值