首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> MySQL 資料庫 >> MySQL 綜合教學

Linux 下 MySQL 5.1 二進制免安裝版完整安裝步驟

     編輯:MySQL 綜合教學

安裝前準備

  • 下載 mysql-VERSION-linux-glibc2.5-x86_64.tar.gz(官網 Generic Linux 下載)。
  • 建立 mysql 用戶組與用戶:groupadd mysql && useradd -r -g mysql -s /bin/false mysql。

解壓與部署

cd /usr/local
tar zxvf /path/to/mysql-VERSION-linux-glibc2.5-x86_64.tar.gz
ln -s mysql-VERSION-linux-glibc2.5-x86_64 mysql
cd mysql

配置檔

cp support-files/my-medium.cnf /etc/my.cnf
# 編輯 /etc/my.cnf 依需求調整:
# [mysqld]
# datadir=/usr/local/mysql/data
# socket=/tmp/mysql.sock
# port=3306
# innodb_buffer_pool_size=1G
# ...

初始化資料目錄與權限

chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data

啟動服務

bin/mysqld_safe --user=mysql &
# 驗證
bin/mysqladmin -u root version
bin/mysql -u root -e "SHOW DATABASES;"

設定 root 密碼

bin/mysqladmin -u root password 'new_strong_password'

註冊系統服務(開機自啟)

cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
service mysqld start

防火牆開放 3306 埠

# iptables
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
service iptables save
# 或 firewalld
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload

驗證連線

netstat -tlnp | grep 3306
mysql -h 127.0.0.1 -u root -p

一鍵指令摘要

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar zxvf mysql-VERSION.tar.gz
ln -s mysql-VERSION mysql
cd mysql
cp support-files/my-medium.cnf /etc/my.cnf
chown -R mysql . ; chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root . ; chown -R mysql data
bin/mysqld_safe --user=mysql &
bin/mysqladmin -u root password 'pass'
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld ; chkconfig --level 345 mysqld on
service mysqld start

結語

二進制免安裝版部署簡單、無編譯依賴、適合快速交付。關鍵點:mysql 用戶權限、mysql_install_db 初始化、my.cnf 配置、服務註冊與防火牆。生產環境請依硬體資源調整 InnoDB 參數、啟用慢查詢日誌、配置主從複寫與備份策略。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved