CentOs下mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz壓縮包的安裝
阿新 • • 發佈:2018-04-16
sorted sql mbo blog 密碼 回車 安裝mysql 下載安裝 window
之前寫過一篇mysql在windows下的安裝(猛擊這兒),linux下用的比較少,最近切換到linux服務器了,發行mysql安裝和windows下有所不同,只記錄壓縮包方式安裝,rpm包類似
1、下載安裝包
這個就不多說了,從官網或者其他地方都可以下載 。
然後上傳到需要安裝的服務器上。
2、解壓縮
理論上可以解壓到任何目錄,我的解壓路徑為 /data/mysql-5.6
1 tar -zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz -C /data/mysql-5.6
3、創建軟連接。
為了執行命令方便,作個連接比較好,當然也可以不做這一步
--連接路徑 cd /usr/local --執行 ln -s /data/mysql-5.6 mysql
4、為mysql創建用戶組
-s /bin/false參數指定mysql用戶僅擁有所有權,而沒有登錄權限
--創建用戶組 groupadd mysql --創建用戶 useradd -r -g mysql -s /bin/false mysql
5、為mysql安裝目錄添加權限
就是給上面創建的用戶分配權限
cd /data/mysql-5.6 chown -R mysql:mysql ./
6、安裝mysql
當前所在路徑是 /data/mysql-5.6.
./mysql_install_db --datadir=/data/mysql-5.6/data --basedir=/data/mysql-5.6 --user=mysql
如果出錯,報“/usr/bin/perl: bad interpreter: No such file or directory”,可以先安裝perl腳本,命令如下:
yum -y install perl perl-devel yum install -y perl-Data-Dumper
完成後再執行上面初始化mysql腳本。。。。
如果是5.7以上版本,可以直接執行命令
./bin/mysqld --user=mysql --basedir=/data/mysql-5.6--datadir=/data/mysql-5.6/data --initialize
執行完仔細看看命令,給root生成一個隨機密碼了。。。
7、配置mysql
默認配置文件所在位置 /etc/my.cnf,執行完步驟6的時候會默認生成一個配置文件
vi /etc/my.cnf
[mysqld] datadir=/data/mysql-5.6/data socket=/data/mysql-5.6/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd # 指定編碼 character-set-server=utf8 collation-server=utf8_general_ci user=mysql [mysqld_safe] log-error=/var/log/mariadb/mariadb.log #可以改為其他路徑,確保路徑存在,並且mysql用戶組有寫入權限 pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d #指定客戶端連接mysql時的socket通信文件路徑 [client] socket=/usr/local/mysql/mysql.sock default-character-set=utf8
8、啟動服務
如果沒有錯誤則啟動成功
./support-files/mysql.server start
9、將mysql進程放入系統進程中,命令如下:
cp support-files/mysql.server /etc/init.d/mysqld
10、重啟mysql
service mysqld restart
11、登陸一下
#第一次登陸沒有密碼,直接回車
./mysql -u root -p
12、修改root密碼
#xxx就是你的新密碼 /data/mysql-5.6/bin/mysqladmin -u root password ‘xxx‘
至此mysql安裝階段完成了。。
CentOs下mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz壓縮包的安裝