mysql命令的基本使用

2021-10-20 00:05:01 字數 1750 閱讀 2039

開啟終端

1、啟動mysql資料庫:

win:net start mysql; 回車

mac:sudo /usr/local/mysql/support-files/mysql.server start; 回車

2、停止mysql資料庫
win:net stop mysql; 回車

mac:sudo /usr/local/mysql/support-files/mysql.server stop;回車

3、通過root登入mysql;
mysql -uroot -p密碼 回車

mysql -uroot -p 回車 然後輸入密碼

4、建立乙個資料庫;
create database [if not exists] 《資料庫名》

[[default] character set 《字符集名》]

[[default] collate 《校對規則名》];

create database "test" character set "utf8_general_ci" collate "utf8_general_ci" 回車

通過 show databases 命令檢視新建立的資料庫

標註:[default] character set:指定資料庫的字符集。指定字符集的目的是為了避免在資料庫中儲存的資料出現亂碼的情況。如果在建立資料庫時不指定字符集,那麼就使用系統的預設字符集。

[default] collate:指定字符集的預設校對規則。

mysql 的字符集(character)和校對規則(collation)是兩個不同的概念。字符集是用來定義 mysql 儲存字串的方式,校對規則定義了比較字串的方式.一般使用utf8_general_ci

5、在新建立的test資料庫中建立乙個表;
use test; 回車

create table tb_empl (id int(11),name varchar(25),deptid int(11),salary float);回車

6、檢視在test資料庫中新建立的表結構
show columns from tb_empl 回車
7、向tb_empl中插入資料
insert into tb_empl  (id,name,deptid,salary) values(1,ysq,'1000',5000);
8、檢視插入的資料
select *from tb_empl;
9、建立乙個普通使用者的資料庫只可以本地訪問,上面的一波操作是在在root的許可權下操作的;
create user "使用者名稱"@"localhost" identified by "密碼";

create user "user01"@"localhost" identified by "12345";

10、建立user01後user01下的資料庫預設是沒法訪問的;通過show database;命令只能看到information_schema;因為user01沒有許可權;授權該user01
grant all on 資料庫.* to 使用者名稱;

grant all on test.* to user01;

11、通知mysql引擎重新整理許可權管理
flush privileges

驗證:select user,host from mysql.user;

MySQL的基本使用命令

常見的命令 登入資料庫 mysql uroot p3306 root為使用者名稱 3306為使用者密碼 退出資料庫 exit 檢視所有資料庫 show databases 建立資料庫 create databases test test為新建立的資料庫名 切換到某個資料庫 use test 建立資料...

mysql 詳細命令 mysql 基本使用命令

一 安裝完畢之後按照如下步驟執行 update user set host where host 127.0.0.1 先關閉mysql並設定密碼 etc init.d mysql stop mysqld safe user mysql skip grant tables skip networkin...

基本MySQL命令

pythonwindows下中文目錄 link filepath.decode utf8 encode gbk 1.怎樣將資料表自增id重新歸零?mysql truncate table 表名 2.在router資料中使用 select count country from routergeoinf...