萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> Ubuntu14.04下編譯安裝Mysql5.7 的例子

Ubuntu14.04下編譯安裝Mysql5.7 的例子

Ubuntu14.04下編譯安裝Mysql5.7 是如何執行命令的呢,今天我們一起來看一篇關於Ubuntu14.04下編譯安裝Mysql5.7 的例子吧。

sudo apt-get install build-essential libncurses5-dev cmake

sudo groupadd mysql

sudo useradd -g mysql mysql

sudo mkdir -p /data/mysql/

sudo mkdir -p /data/mysql/data/

wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7...

tar -zxf mysql-5.7.11.tar.gz

sh BUILD/autorun.sh

# MySQL從5.5版本開始,通過./configure進行編譯配置方式已經被取消,取而代之的是cmake工具,下面這個只是用來對比寫cmake用的,並不能執行

./configure --prefix=/usr/local/mysql/ --localstatedir=/data/mysql/data --enable-assembler --without-isam --with-unix-socket-path=/data/mysql/data --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-plugins=partition,innobase --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=utf8,gbk --with-big-tables --without-debug

# 要不要和apt-get安裝一樣,mysql放在 /var/lib/mysql/,sock放在 /var/run/mysqld/

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=utf8,gbk -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_EMBEDDED_SERVER=0

mysql5.7需要最新版的boost,如果提示:

-- Could not find (the correct version of) boost.

-- MySQL currently requires boost_1_59_0

到 http://www.boost.org 上面下載 boost_1_59_0.tar.gz

tar -zxvf boost_1_59_0.tar.gz

cd boost_1_59_0

# 編譯生成boost的編譯引擎

./bootstrap.sh

# 開始編譯boost程序,這裡需要十幾分鐘,沒有進度條,不像make,蛋疼死了,完成後就代表安裝成功了。

./bjam --prefix==./prefix/install

# 安裝boost

./b2 install

# 回到mysql源碼目錄

cd ../mysql-5.7.11

# 開啟4個線程編譯

make -j4

# 安裝

make install

如果到 53% 的時候出現錯誤:

make[2]: *** [storage/perfschema/unittest/pfs_connect_attr-t] Error 1

make[1]: *** [storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/all] Error 2

加上參數 -DWITH_EMBEDDED_SERVER=0

原因是它默認以嵌入式方式編譯了:https://bugs.launchpad.net/percona-server/+bug/798050

The errors are in embedded which is not supported in Percona Server. Please try building with -DWITH_EMBEDDED_SERVER=OFF

Changed in percona-server:

status:New → Invalid

# 修改 mysql 安裝目錄和數據目錄權限

sudo chown -R mysql:mysql /usr/local/mysql

sudo chown -R mysql:mysql /data/mysql/

cd /usr/local/mysql

sudo cp support-files/my-default.cnf /etc/my.cnf

sudo cp support-files/mysql.server /etc/init.d/mysqld

# 生成數據庫數據

sudo /usr/local/mysql/bin/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql

# 配置環境變量,否則 mysql 客戶端命令不可用

vim /etc/profile,在文件末尾添加

PATH=/usr/local/mysql/bin:$PATH

export PATH

source /etc/profile

# 修改密碼:MySQL5.7在安裝完後,第一次啟動時,會在root目錄下生產一個隨機的密碼,文件名為

.mysql_secret

cat /root/.mysql_secret

用得到的隨機密碼登陸,然後通過以下命令修改密碼

SET PASSWORD = PASSWORD('new password');

不需要 flush privileges;

問題:

1、[Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.

解決:283行,mysqld_safe --secure-file-priv=NULL

2、[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

解決:/etc/my.cnf 加上

explicit_defaults_for_timestamp = 1

3、skip-name-resolve是禁用dns解析,打開之後就只能用ip,否則出現下面提示

[Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.

[Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.

[Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.

[Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.

[Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.

解決:刪除非IP登錄的用戶

mysql> use mysql;
mysql> delete from user where HOST=’localhost.localdomain’;

copyright © 萬盛學電腦網 all rights reserved