編譯安裝mysql5.5及以上的版本須要用cmake, 提早裝好cmakemysql
下載mysql5.7.23,解壓縮,進入目錄sql
wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/mysql-5.7.23.tar.gz tar zxvf mysql-5.7.23.tar.gz cd mysql-5.7.23
個人編譯參數bash
cmake -DCMAKE_INSTALL_PREFIX=../mysql -DMYSQL_UNIX_ADDR=../mysql/var/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=../mysql/data -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1
執行socket
make && make install
通過漫長的編譯完成後,進入mysql安裝目錄code
初始化server
bin/mysqld --no-defaults --initialize --basedir=/home/liuzhongliang/mysql --datadir=/home/liuzhongliang/mysql/data --lc-messages=zh_CN --explicit_defaults_for_timestamp --character-set-server=utf8 --character-set-filesystem=utf8 --port=3361 --pid-file=/home/liuzhongliang/mysql/var/run/mysql.pid --socket=/home/liuzhongliang/mysql/var/mysql.sock --log-error=/home/liuzhongliang/mysql/log/mysql.log --secure-file-priv='' --read-only=0
注意 ip
--secure-file-priv 是置頂容許進行數據導入導出的文件目錄,賦值爲''(不是null),容許任何文件目錄
--read-only=0 關閉只讀模式,我一開始初始化後,用獲得的root帳號和密碼登陸不上去,追查出了原來默認是隻讀模式,加上關閉只讀模式的參數進行初始化,才登陸成功了。
初始化完成後,會獲得默認的root帳號和密碼ci
固然後面的哪些配置參數能夠放到一個配置文件裏來代替,個人mysql 配置文件(/home/liuzhongliang/mysql/my.cnf)get
[mysqld] basedir = /home/liuzhongliang/mysql datadir = /home/liuzhongliang/mysql/data open-files-limit= 1024 character-set-server= utf8 [mysqld_safe] explicit_defaults_for_timestamp skip-grant-tables log-error=/home/liuzhongliang/mysql/log/mysql.log pid-file=/home/liuzhongliang/mysql/var/run/mysql.pid port = 3361 socket = /home/liuzhongliang/mysql/var/mysql.sock [client] socket=/home/liuzhongliang/mysql/var/mysql.sock character-set-server=utf8
啓動mysqlit
./bin/mysqld_safe --defaults-file=my.cnf & >/dev/null
修改密碼
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');