我們在Windows系統(tǒng)中安裝過MySQL數(shù)據(jù)庫,那么如何在Ubuntu系統(tǒng)中安裝呢?下面我給大家分享演示一下。
專注于為中小企業(yè)提供網(wǎng)站制作、網(wǎng)站設(shè)計(jì)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)常山免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了近千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
工具/材料
Ubuntu
01
首先我們需要登錄MySQL的官方平臺下載Ubuntu的安裝包,如下圖所示,大家選擇紅框中的安裝包即可
02
接下來打開Ubuntu中的命令行,執(zhí)行apt install numactl安裝MySQL的依賴庫numactl,如下圖所示
03
然后執(zhí)行apt install命令繼續(xù)安裝依賴包libaio-dev,如下圖所示
04
接下來我們運(yùn)用tar命令解壓剛才下載的mysql壓縮包,如下圖所示
05
接著我們需要通過groupadd命令給Ubuntu系統(tǒng)添加一個(gè)mysql的用戶組,如下圖所示
06
然后添加一個(gè)mysql用戶到mysql用戶組中,如下圖所示,這里主要用了useradd命令
07
接下來我們需要將解壓后的壓縮包移動(dòng)到/usr/local/mysql文件夾下面,如下圖所示
08
然后給移動(dòng)后的文件夾添加目錄權(quán)限到mysql用戶組,如下圖所示
09
接下來我們就可以對mysql數(shù)據(jù)庫執(zhí)行初始化命令了,如下圖所示
10
最后我們在命令行開啟MySQL服務(wù)即可完成數(shù)據(jù)庫的安裝了,如下圖所示
1
安裝:
apt-get
install
mysql-server
2
設(shè)置允許遠(yuǎn)程登錄
修改/etc/mysql/my.cnf(此文件為mysql的配置文件)。將文件中的binding-address=127.0.0.1注釋掉。
從本機(jī)登陸mysql:mysql
-u
root
-p
use
mysql;
設(shè)置允許所有主機(jī)連接到Mysql,執(zhí)行命令:grant
all
privileges
on
*.*
to
root@"%"
identified
by
"root用戶的密碼"
with
grant
option;
3
重啟mysql
/etc/init.d/mysql
restart
*注:/etc/init.d/mysql
start|stop|restart可以啟動(dòng)/停止/重啟
4
設(shè)置開機(jī)自啟動(dòng)
把啟動(dòng)命令(/etc/init.d/mysql
start)加入/etc/rc.local文件中
5
設(shè)置Mysql字符集:
創(chuàng)建數(shù)據(jù)庫時(shí)指定字符集:create
database
mydb
character
set
utf-8;
查看當(dāng)前字符集:show
variables
like
'character%';
修改當(dāng)前數(shù)據(jù)庫的字符集:
mysql
SET
character_set_client
=
utf8
;mysql
SET
character_set_connection
=
utf8
;mysql
SET
character_set_database
=
utf8
;mysql
SET
character_set_results
=
utf8
;mysql
SET
character_set_server
=
utf8
;mysql
SET
NAMES
utf8;
//這條語句會(huì)改變
character_set_client
character_connection
character_results這三個(gè)
的字符集
Ubuntu上安裝MySQL最簡單的方法還是使用apt-get命令,這個(gè)命令需要用root用戶身份執(zhí)行,安裝命令是這樣的:
apt-get install mysql-server mysql-client
接下來啟動(dòng)MySQL來驗(yàn)證是否安裝成功,啟動(dòng)MySQL的命令是這樣的:
/etc/init.d/mysql restart
最后用如下命令來檢查MySQL是否已經(jīng)正常啟動(dòng)了:
netstat -tap | grep mysql
如果MySQL啟動(dòng)的話,這條命令應(yīng)該有輸出,否則沒有任何輸出。
在Linux Ubuntu中安裝MySQL數(shù)據(jù)庫
#安裝MySQL服務(wù)器端
~ sudo apt-get install mysql-server
安裝過程會(huì)彈出提示框,輸入root用戶的密碼,我在這里設(shè)置密碼為mysql。
安裝完成后,MySQL服務(wù)器會(huì)自動(dòng)啟動(dòng),我們檢查MySQL服務(wù)器程序
# 檢查MySQL服務(wù)器系統(tǒng)進(jìn)程
~ ps -aux|grep mysql
mysql 3205 2.0 0.5 549896 44092 ? Ssl 20:10 0:00 /usr/sbin/mysqld
conan 3360 0.0 0.0 11064 928 pts/0 S+ 20:10 0:00 grep --color=auto mysql
# 檢查MySQL服務(wù)器占用端口
~ netstat -nlt|grep 3306
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
# 通過啟動(dòng)命令檢查MySQL服務(wù)器狀態(tài)
~ sudo /etc/init.d/mysql status
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql status
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the status(8) utility, e.g. status mysql
mysql start/running, process 3205
# 通過系統(tǒng)服務(wù)命令檢查MySQL服務(wù)器狀態(tài)
~ service mysql status
mysql start/running, process 3205
3. 通過命令行客戶端訪問MySQL
安裝MySQL服務(wù)器,會(huì)自動(dòng)地一起安裝MySQL命令行客戶端程序。
在本機(jī)輸入mysql命令就可以啟動(dòng),客戶端程序訪問MySQL服務(wù)器。
~ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.5.35-0ubuntu0.12.04.2 (Ubuntu)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql
使用戶名和密碼,登陸服務(wù)器
~ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.5.35-0ubuntu0.12.04.2 (Ubuntu)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql
Ubuntu安裝MySQL用apt-get命令最方便了,用root用戶身份執(zhí)行如下命令,才是Ubuntu系統(tǒng)上正確的安裝方式:
apt-get install mysql-server mysql-client
然后輸入命令啟動(dòng)MySQL:
/etc/init.d/mysql restart
最后查看MySQL是否正常啟動(dòng),如果正常啟動(dòng)就表示安裝成功了:
netstat -tap | grep mysql
如果MySQL啟動(dòng)了的話,這條命令應(yīng)該有輸出,否則什么輸出也沒有。
新聞名稱:烏班圖怎么添加mysql,烏班圖怎么添加網(wǎng)口
瀏覽地址:http://jinyejixie.com/article6/dssoeig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、網(wǎng)站改版、標(biāo)簽優(yōu)化、微信小程序、網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)