MySql基本操作

2021-09-03 08:18:59 字數 2511 閱讀 8407

我們發現預設的有些亂,為了保證後續的開發操作不出現亂碼,我們設定所有的字符集為

utf8

以下操作只是臨時的,也就是對當前的會話有效,如果以後不想再修改,就加上關鍵字 global

比如 set global character_set_client=utf8;

執行命令:

set character_set_client=utf8;

set character_set_connection=utf8;

set character_set_database=utf8;

set character_set_results=utf8;

set character_set_filesystem=utf8;

create database licm;

show databases;

檢視指定資料庫:

注意!!!刪除資料是不可逆的,刪除的過程是級聯的操作,本地的資料庫資料夾也會一起

被刪除,所以刪除資料庫的時候,一定要備份。 

create table 表名 () charset utf8; 帶上字符集是個好習慣。後面的例子我基本上都會帶上。

例如:create table if not exists zhangzq(

id int primary key,

name varchar(30),

age int(3)

)charset=utf8;

if not exists: 如果表名不存在,那麼就建立,否則不執行建立**: 檢查功能。

建立之前記得指定資料庫,不然會報錯。 no database selected;

當然也可以這樣建立 資料庫名.表名。

show tables;

模糊查詢表:

show tables like '%zhan%'

檢視表的建表語句:

檢視表結構 desc/describe/show columns from 表名;

更新表,包括更新表名和表字段兩種操作。

更新表名

更新之前 檢視一下當前資料庫下的表名。

rename table 表名 to 新錶名;

表的字符集 alter table 表名 charset = 字符集;

新增字段:

修改欄位名:

刪除字段:

***在資料庫中的所有刪除 drop 操作均不可逆。

alter table student drop age2;

刪除表:

drop table 表名...  可以指定多張表。

***在資料庫中的所有刪除

操作均不可逆。

刪除操作之後對應的資料庫檔案也會被刪除,並且不可恢復。

mysql基本操作 MySQL基本操作

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 1.1 登入mysql mysql u root p 密碼 1.2 建立使用者 mysql insert into mysql.user host,user,passwor...

mysql 基本操作 mysql基本操作

mysql 建立表,並設定主鍵自增 create table log logid int 4 primary key not null auto increment,logtitle varchar 32 not null logcontent varchar 160 not null logtim...

mysql基本操作

1,檢視資料庫狀態 及啟動停止 etc init.d mysqld status etc init.d mysqld start etc init.d mysqld stop 2,給使用者配置初始密碼123456 mysqladmin u root password 123456 3,修改root使...