環境 cenos7
- 準備工作
- 檢測名稱
hostname -f
- 更新系統
sudo yum update
- 安裝Wget
yum install wget
安裝
- 下載下傳并添加存儲庫,然後進行更新
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update
- 安裝MySQL 并啟動, 安裝過程中系統将詢問您是否要接受.rpm檔案的GPG驗證結果。如果沒有出現錯誤或不比對,請輸入y
sudo yum install mysql-server sudo systemctl start mysqld
- 初始化服務
您可以選擇更改MySQL root密碼,删除匿名使用者帳戶,禁用localhost之外的root登入,以及删除測試資料庫。建議您回答yes這些選項。您可以在 MySQL參考手冊 中閱讀有關該腳本的更多資訊。sudo mysql_secure_installation
使用
- 以root使用者身份登入MySQL
mysql -u root -p
- 檢視幫助中心
\h
For information about MySQL products and services, visit: http://www.mysql.com/ For developer information, including the MySQL Reference Manual, visit: http://dev.mysql.com/ To buy MySQL Enterprise support, training, or other products, visit: https://shop.mysql.com/ List of all MySQL commands: Note that all text commands must be first on line and end with ';' ? (\?) Synonym for `help'. clear (\c) Clear the current input statement. connect (\r) Reconnect to the server. Optional arguments are db and host. delimiter (\d) Set statement delimiter. edit (\e) Edit command with $EDITOR. ego (\G) Send command to mysql server, display result vertically. exit (\q) Exit mysql. Same as quit. go (\g) Send command to mysql server. help (\h) Display this help. nopager (\n) Disable pager, print to stdout. notee (\t) Don't write into outfile. pager (\P) Set PAGER [to_pager]. Print the query results via PAGER. print (\p) Print current command. prompt (\R) Change your mysql prompt. quit (\q) Quit mysql. rehash (\#) Rebuild completion hash. source (\.) Execute an SQL script file. Takes a file name as an argument. status (\s) Get status information from the server. system (\!) Execute a system shell command. tee (\T) Set outfile [to_outfile]. Append everything into given outfile. use (\u) Use another database. Takes database name as argument. charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets. warnings (\W) Show warnings after every statement. nowarning (\w) Don't show warnings after every statement. For server side help, type 'help contents'
- 在下面的示例中,test_db是資料庫的名稱,tname是使用者,password是使用者的密碼
create database test_db; create user 'tname'@'localhost' identified by 'password'; grant all on test_db.* to 'tname' identified by 'password';
- 退出
exit;