Ubuntu14.04系统编译安装Mysql5.7教程

作者:袖梨 2022-06-30


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’;

相关文章

精彩推荐