Linux 伺服器安裝MySQL資料庫

來源:互聯網
上載者:User

標籤:

安裝包:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz

使用xshell串連linux伺服器,使用root使用者名稱登入,依次執行以下命令:

======================================================

/usr/sbin/groupadd mysql   【添加mysql組】

/usr/sbin/useradd -d /var/lib/mysql -s /sbin/nologin -g mysql mysql

 

mkdir -p /usr/local/src/mysql 【建立mysql檔案夾】

 

cd /   【開啟上傳安裝包的目錄】

mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz 【上傳安裝包到伺服器的根目錄下】

mv  mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz  /usr/local/src/mysql【根目錄的安裝包移動到檔案夾下】

 

cd  /usr/local/src/mysql  【開啟目錄】

tar -zxvf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz  【解壓安裝包】

cp mysql-5.6.30-linux-glibc2.5-x86_64 /usr/local/mysql -r  【複製檔案】

 

cd /usr/local  【開啟目錄】

chown -R mysql:mysql mysql/

 

cd /usr/local/mysql/scripts/  【開啟目錄】

./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data【執行指令碼】

 

cd /usr/local/mysql/support-files  【開啟目錄】

cp my-default.cnf /etc/my.cnf【複製檔案到新的路徑下及檔案名稱】

    cp: overwrite `/etc/my.cnf‘?Y【Y】

cp mysql.server /etc/init.d/mysql【複製檔案到新的路徑下】

 

vim /etc/profile【編輯軟體運行環境】
vim i(編輯一些內容) esc(進入normal) w(儲存檔案) q(不儲存退出檔案)
###############################################################
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
###############################################################
source /etc/profile

 

chkconfig --add mysql

chkconfig mysql on


service mysql start
/usr/local/mysql/bin/mysqladmin -u root password ‘rootroot‘【修改資料庫root的密碼】


grant all privileges on tdcdb.* to ‘root‘@‘%‘ identified by ‘rootroot‘ 【給mysql使用者指派許可權】
flush privileges;

 

vim /etc/sysconfig/iptables【編輯訪問連接埠號碼】
###############################################################
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(添加3306的連接埠號碼)
###############################################################
service iptables restart
netstat -ntlp

 

mysql -u root -p (命令未找到使用: ln -s /usr/local/mysql/bin/mysql /usr/bin)
create user ‘tdc‘@‘%‘ identified by ‘[email protected]‘;【建立資料庫訪問使用者】
create database if not exists `tdcdb`;【建立資料庫】

grant all privileges on tdcdb.* to ‘tdc‘@‘%‘ identified by ‘[email protected]‘;【給tdc使用者指派訪問密碼】
flush privileges;

 

vi /etc/my.cnf【編輯設定檔,支援語言設定】
###############################
[client]
default-character-set=utf8

[mysqld]
character-set-server=utf8

[mysql]
default-character-set=utf8
###############################
service mysql stop【重新啟動mysql服務】
service mysql start

======================================================

linux 常用命令:

pwd:查看當前路徑

ll:2個小寫L,查看目前的目錄下的所有檔案

cd:開啟目錄,包括路徑地址及檔案夾

vi 檔案名稱:編輯linux下的檔案,使用大寫的【I】命令來進行編輯,編輯完成後點擊【ESC】按鈕跳出編輯,輸入【:wq!】命令來退出儲存;

注意:linux的檔案不能開啟直接修改,只能通過vi命令進行修改

======================================================

卸載程式的方式:

ps -ef | grep mysql
/etc/init.d/mysql status
whereis mysql
find / -name mysql【找到所有檔案名稱為mysql的檔案清單】
rm -rf /usr/local/mysql/【使用rm命令來移除列表中的檔案】
rm -rf /etc/my.cnf【使用rm命令來移除列表中的檔案】

Linux 伺服器安裝MySQL資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.