在Linux下安裝MySQL源碼需要以下步驟:
1.下載MySQL源碼
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.25.tar.gz
2.安裝依賴包
sudo apt-get install build-essential cmake libncurses5-dev libncursesw5-dev libssl-dev libmysqlclient-dev libmariadbclient-dev
3.解壓源碼文件
tar -zxvf mysql-8.0.25.tar.gz cd mysql-8.0.25
4.創(chuàng)建安裝目錄
sudo mkdir -p /usr/local/mysql sudo chown -R $(whoami) /usr/local/mysql
5.用cmake編譯源碼
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DMYSQL_SKIP_NAME_RESOLVE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_BOOST=/usr/local \ -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \ -DDEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci \ -DWITH_EMBEDDED_SERVER=OFF
6.安裝MySQL
make sudo make install
7.配置MySQL
sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server sudo chmod +x /etc/init.d/mysql.server sudo update-rc.d mysql.server defaults sudo printf '[mysqld]\nbasedir=/usr/local/mysql\ndatadir=/usr/local/mysql/data\nsocket=/var/run/mysqld/mysqld.sock' >/etc/my.cnf sudo useradd -r mysql -s /bin/false cd /usr/local/mysql sudo chown -R mysql:mysql . sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data sudo bin/mysql_ssl_rsa_setup sudo /etc/init.d/mysql.server start
8.設(shè)置MySQL密碼
sudo /usr/local/mysql/bin/mysql_secure_installation
安裝完成后,你就可以在 Linux 下愉快地使用 MySQL 了!