網(wǎng)站開發(fā)架構網(wǎng)站seo快速優(yōu)化
前言
MySQL是一個開源數(shù)據(jù)庫管理系統(tǒng),通常作為流行的LAMP(Linux,Apache,MySQL,PHP / Python / Perl)堆棧的一部分安裝。它使用關系數(shù)據(jù)庫和SQL(結構化查詢語言)來管理其數(shù)據(jù)。
安裝MySQL
更新列表
sudo apt-get update
安裝MySQL服務器?
sudo apt-get install mysql-server
?安裝MySQL客戶端
sudo apt-get install mysql-client
在安裝過程中,系統(tǒng)將提示您創(chuàng)建root密碼。選擇一個安全的,并確保記住它,因為后面需要用到這個密碼。
mysql-server和mysql-client區(qū)別
mysql-server 是MySQL核心程序?qū)惭bMySQL數(shù)據(jù)庫服務器,用于生成管理多個數(shù)據(jù)庫實例,持久保存數(shù)據(jù)并為其提供查詢接口(SQL),供不同客戶端調(diào)用。
mysql-client 是操作數(shù)據(jù)庫實例的工具,允許連接到MySQL服務器使用該查詢接口。它將為您提供MySQL命令行程序。
如果只需要連接到遠程服務器并運行查詢,只安裝mysql-client就可以了。如果是服務器只提供連接服務的只需要安裝mysql-server
?
配置MySQL
運行MySQL初始化安全腳本
sudo mysql_secure_installation
mysql_secure_installation腳本設置的東西:更改root密碼、移除MySQL的匿名用戶、禁止root遠程登錄、刪除test數(shù)據(jù)庫和重新加載權限。除了詢問是否要更改root密碼時,看情況是否需要更改,其余的問題都可以按Y,然后ENTER接受所有后續(xù)問題的默認值。使用上面的這些選項可以提高MySQL的安全。
測試MySQL
systemctl status mysql.service
以下內(nèi)容的輸出:
MySQL數(shù)據(jù)庫基本使用
啟動MySQL數(shù)據(jù)庫服務
?sudo service mysql start? ? ?或? ? sudo systemctl start mysql.service
重啟MySQL數(shù)據(jù)庫服務
sudo service mysql restart? ? 或? ? ?sudo systemctl restart mysql.service
停止MySQL數(shù)據(jù)庫服務
sudo service mysql stop? ? ? 或? ?sudo systemctl stop mysql.service
查看MySQL運行狀態(tài)
sudo service mysql status? ?或? ?sudo systemctl status mysql.service
設置MySQL服務開機自啟動
sudo service mysql enable
或
sudo systemctl enable mysql.service
停止MySQL服務開機自啟動?
sudo service mysql disable? ?或? ?sudo systemctl disable mysql.service
MySQL的配置文件
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
MySQL查看信息
使用MySQL時,需要了解當前數(shù)據(jù)庫的情況,例如當前的數(shù)據(jù)庫大小、字符集、用戶等等。下面總結了一些查看數(shù)據(jù)庫相關信息的命令。
查看顯示所有數(shù)據(jù)庫
show databases;
查看數(shù)據(jù)庫使用端口
show variables like 'port';
查看數(shù)據(jù)庫的表信息
show tables;
查看表結構
show columns from table_name;? ? ?或? ? describe table_name;