標籤:centos 方式安裝 修改root密碼 end character windows rest eve emd
之前寫過一篇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.6chown -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-develyum 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/datasocket=/data/mysql-5.6/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-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=utf8collation-server=utf8_general_ciuser=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.sockdefault-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壓縮包的安裝