標籤:
一、登入
開啟終端,輸入/usr/local/mysql/bin/mysql -u root -p
初次進入mysql,密碼為空白。當出現mysql>提示符時,表示你已經進入mysql中。鍵入exit退出mysql。
二、更改Mysqlroot使用者密碼
更改mysql root 使用者密碼,在終端輸入/usr/local/mysql/bin/mysqladmin -u root password新密碼
設定新的密碼,再次輸入/usr/local/mysql/bin/mysql -u root -p登入:
三、建立使用者
以root身份登入mysql:
建立一個使用者,鍵入insert into mysql.user(Host,User,Password) values("localhost","新使用者",password("密碼"));
重新整理系統許可權表,鍵入 flush privileges;
這樣就建立了一個使用者名稱為Lands,密碼為Lands的使用者。嘗試用新使用者密碼登入:
四、刪除使用者
登入root 賬戶。
刪除使用者,鍵入 DELTE FROM mysql.user WHERE User="使用者名稱";
重新整理許可權表,鍵入 flush privileges;
五、修改指定使用者密碼
登入root 賬戶。
修改指定使用者密碼,鍵入update mysql.user set password=password("新密碼") where User="使用者名稱" and Host="localhost";
重新整理許可權表,鍵入 flush privileges;
六、為使用者建立資料庫
登入root 賬戶。 先建立一個資料庫:鍵入 create database 資料庫名;
然後為使用者添加操作資料庫的許可權,鍵入 grant all privileges on 資料庫名.* to 使用者名稱@localhost identified by ‘使用者名稱‘;
重新整理許可權表,鍵入 flush privileges;
如果只指定部分許可權給使用者,鍵入grant select,update on 資料庫名.* to 使用者名稱@localhost identified by ‘使用者名稱‘; 重新整理許可權表,
鍵入 flush privileges;
七、操作資料庫
登入root 賬戶。
1、建立一個新的資料庫,鍵入 create database 資料庫名;
2、開啟一個資料庫,鍵入 use 資料庫名;
3、顯示資料庫中所有的資料表,鍵入 show tables;
4、建立一個資料庫表,鍵入create table資料表名(欄位1 欄位類型, 欄位2 欄位類型);
5、顯示表的結構,鍵入 describe 資料表名;
6、在表中插入資料,鍵入 insert into 資料表名 value("欄位值1", "欄位值2");
7、更新表中資料,鍵入 update 資料表名 set 欄位1=欄位值1 where 篩選條件;
8、刪除表中資料,鍵入 delete from 資料表名 where 查詢條件;
9、清空表中資料,鍵入 delete from 資料表名;
10、刪除資料表,鍵入 drop table 資料表名;
MySQL for mac使用記錄