進入http://mirrors.163.com/mysql/Downloads/MySQL-8.0下,查找你喜歡的mysql版本mysql
使用wget下載sql
1.安裝依賴vim
sudo apt-get install gcc g++ make cmake libssl-dev libncurses5-dev pkg-config -y
2.cmake、make、make install出錯時ui
make clean sudo rm CMakeCache.txt
3.編譯很耗內存,至少1G,須要增長交換空間,機器好的能夠忽略這一步es5
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 sudo mkswap /swapfile sudo swapon /swapfile sudo swapon -s
增長了仍是不夠時vagrant
sudo swapoff -a
再次執行上面的命令code
4.添加用戶組、文件夾以及權限server
sudo groupadd mysql sudo useradd -g mysql mysql sudo mkdir -p /usr/local/mysql/data sudo chown -R mysql:mysql /usr/local/mysql
5.進入mysql源碼目錄再建立build目錄,而後進入build目錄(make的時候會產生不少文件及文件夾目錄)blog
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/home/vagrant/src/mysql-8.0.17/boost -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_SSL=system -DFORCE_INSOURCE_BUILD=1 && make && sudo make install
6.初始化mysql生成root帳號密碼內存
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
7.把mysqld放到/etc/init.d/下,方便使用
sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld sudo chmod +x /etc/init.d/mysqld sudo vim /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/usr/local/mysql/data sudo update-rc.d mysqld defaults sudo service mysqld start ps -ef | grep mysqld
8.登陸mysql
export PATH=$PATH:/usr/local/mysql/bin mysql -uroot -p ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼'; 如 ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
make的時候會很是慢,耐心等待!