首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

晓桂科技技术小共享,MySQL基础操作

Mysql基础操作

设置密码

mysqladmin -uroot password "123456“(没有密码的情况)

mysqladmin -uroot password "456789" -p123456(知道原密码)

update mysql.user set password=password("123456") where user="root" and host="localhost";

(不知道密码时)/my.cnf skip-grant-tables

flush privileges;(刷新权限表)

set password from 'root'@'localhost'=password('123456');(不用刷新权限表)

数据库授权

grant all on *.* to mas@localhost identified by "123456" with grant option;

(给mas用户授予root权限)

grant write on database.* to user@host identified by "pass";

(user在host主机对database库有写权限)

grant select,insert,update,delete on *.* to user@"%" identified by "123456";

(user用户在任何主机上对所有数据库有这些权限)

grant select,insert,update,delete on mydatabase.* to myuser@localhonst identified by "123456";(myuser用户通过密码123456,对mydatabase库进行该权限操作)

增加一个用户custom,他能从主机localhost,server,domain和whitehouse.gov连接。

它只从localhost存取bankacount数据库,从whitehost.gov存取expenses数据库和从所有3台主机存取customer数据库。

它想要从所有3台主机上使用口令stuipid.

shell> mysql --user=root mysql

grant select,insert,update,delete,creat,drop on bankaccount.* to custom@localhost identified by 'stuipid;

grant select,insert,updete,delete,creat,drop on custom@'%' identified by 'stupid';

创建库

create database mas;(不指定字符集)

drop database mas(删除库)

创建表

create table mas (id int);(使用默认引擎)

create table mas (id int) engine=memory; (指定引擎)

drop table mas;(删除表)

show databases;(查看有哪些库)

use 库名;(进入该库)

select databases();(查看进入了那个库(pwd))

show tables; (查看当前库有哪些表)

select user();(查看当前登录用户)

select * from mas;(查看表内容)

desc 表名;(描述表结构)

rename table mas1 to mas2; (重命名表名)

show variables like "character%"(查看数据库字符集)

insert into aaa.emp(emp_id,ename) values (1,‘aaa');

insert into aaa.emp(emp_id,ename) values (2,‘bbb');

insert into aaa.emp(emp_id,ename) values (3,‘ccc');

晓桂科技

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180222A0F4W700?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券