Linux下MySQL的一些操作

來源:互聯網
上載者:User

1、Linux下啟動Mysql的命令:
/etc/init.d/mysql start
2、關閉Mysql的命令:
/etc/init.d/mysql shutdown
3、重啟Mysql的命令:
/etc/init.d/mysql restart
4、建立使用者:
grant 許可權(all代表所有許可權) on database_name.* to userNmae@"%" identified by "Password"
GRANT privileges (columns) ON what TO user IDENTIFIED BY "password" WITH GRANT OPTION
如果建立使用者後或者Update Mysql-User表後許可權的設定不生效,可以執行flush privileges;就OK!

mysql>grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by '123';
給來自10.163.225.87的使用者joe分配可對資料庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。

mysql>grant all privileges on vtdc.* to joe@10.163.225.87 identified by '123';
給來自10.163.225.87的使用者joe分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on *.* to joe@10.163.225.87 identified by '123';
給來自10.163.225.87的使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on *.* to joe@localhost identified by '123';
給本機使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。

5、匯入資料:
在mysql的命令列 source /root/daoru.sql;

6、Linux下解決Mysql資料庫大小寫問題:
修改/etc/my.cnf檔案,在[mysqld]下加一行:lower_case_table_names=1 (修改完後需要重啟動mysql才會生效)
如果/etc下沒有my.cnf檔案,就把/usr/share/mysql目錄下的my-medium.cnf拷貝到/etc目錄下,重新命名為my.cnf,然後再修改,最後重啟Mysql就OK了.可以在Mysql的命令列檢查當前的設定是否區分大小寫:

mysql> show variables like '%case_table%';

+------------------------+-------+

| Variable_name          | Value |

+------------------------+-------+

| lower_case_table_names | 1     |

+------------------------+-------+
(0:區分;1:不區分)

7、自動啟動
1)察看mysql是否在自動啟動列表中
[root@test1 local]# /sbin/chkconfig –list
2)把MySQL添加到你系統的啟動服務組裡面去
[root@test1 local]# /sbin/chkconfig – add mysql
3)把MySQL從啟動服務組裡面刪除。
[root@test1 local]# /sbin/chkconfig – del mysql

8、修改Mysql字元編碼:

開啟設定檔/etc/my.cnf(修改完後需要重啟動mysql才會生效)
在[client] 添加   default-character-set=utf8 預設字元集為utf8
在[mysqld] 添加   default-character-set=utf8 預設字元集為utf8
init_connect='SET NAMES utf8' (設定串連mysql資料庫時使用utf8編碼,以讓mysql資料庫為utf8運行)

mysql> show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

9、查看Mysql資料庫裡已經建立好的預存程序和儲存函數:

SHOW PROCEDURE STATUS
SHOW FUNCTION STATUS
查看某個預存程序的代碼:show create procedure status

對於預存程序,如果是root使用者建立的,其他使用者則無法訪問,可以用如下的方式來解決:
mysql> SHOW CREATE PROCEDURE `database`.`procedure_name`\G
mysql> GRANT select ON mysql.proc to user@'host' IDENTIFIED BY 'passwd';
注意:identified by 'passwd' 的用途是修改密碼,如果不想修改密碼的話就不要加這句話.

10、查看錶結構:desc table_name;
Linux下查看到3306連接埠的tcp連結:netstat -an | grep 3306
Mysql命令列下查看串連池的連結:show processlist
Linux下遠程連結Mysql資料庫:mysql -h192.168.1.1 -u -p

11、mysql的使用者權限

首先是使用者的建立,可以用grant
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

也可以直接插入:
INSERT INTO user (Host,User,Password) VALUES('localhost','dummy',PASSWORD('some_pass'));
FLUSH PRIVILEGES;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.