mysql(编译安装篇)

发表于 2019-09-19  338 次阅读


查看系统版本
1
2
cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)
安装所需依赖
1
yum -y install gcc cmake make gcc-c++ ncurses-devel openssl-devel bison ncurses chkconfig lsof
卸载系统自带Mariadb及删除遗留的配置文件
1
2
3
4
5
6
7
8
#查看centos 默认安装的mariadb 
[root@VM_0_15_centos ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
# 强制卸载mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
#删除对应的mariadb配置文件
rm -rf /etc/my.cnf
下载MySql文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#进入到/usr/local/src
cd /usr/local/src
#下载文件(因mysql5.7之后必须要安装boost库,所以这里直接下载带boost的mysql源码)
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.23.tar.gz

#下载成功
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.23.tar.gz
--2018-10-19 22:46:26--  https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.23.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.56.25.233
Connecting to cdn.mysql.com (cdn.mysql.com)|23.56.25.233|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 49025014 (47M) [application/x-tar-gz]
Saving to: ‘mysql-boost-5.7.23.tar.gz’

100%[==============================================================================================>] 49,025,014   523KB/s   in 64s    

2018-10-19 22:47:47 (747 KB/s) - ‘mysql-boost-5.7.23.tar.gz’ saved [49025014/49025014]

#解压文件
tar zxvf mysql-boost-5.7.23.tar.gz
#进入目录
cd mysql-5.7.23
#编译参数
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_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DENABLE_DOWNLOADS=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled -DWITH_BOOST=boost

#初始化完成

-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- COMPILE_DEFINITIONS: _GNU_SOURCE;_FILE_OFFSET_BITS=64;HAVE_CONFIG_H;HAVE_LIBEVENT1
-- CMAKE_C_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement
-- CMAKE_CXX_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter
-- CMAKE_C_LINK_FLAGS: 
-- CMAKE_CXX_LINK_FLAGS: 
-- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/mysql-5.7.23
编译安装
1
make && make install
添加mysql用户和用户组
1
2
groupadd mysql
useradd mysql -g mysql -M -s /sbin/nologin
给mysql用户授权mysql 文件夹
1
chown -R mysql:mysql /usr/local/mysql/
拷贝启动文件
1
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
初始化数据库
1
2
#使用-initialize会生成随机密码,使用-initialize-insecure生成空密码,这里选择生成空密码。
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql
启动MySql
1
2
3
4
#启动MySql
/etc/init.d/mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/VM_0_15_centos.err'.
SUCCESS!
添加至环境变量
1
2
3
4
5
6
#使其永久生效,把安装目录添加至环境变量
vim /etc/profile
#文件最后一行添加进去
export PATH=$PATH:/usr/local/mysql/bin
#马上生效
source /etc/profile
登陆mysql
1
mysql -uroot -p
修改密码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#查看数据库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
#修改root密码为123456
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
#退出mysql,重新登陆生效
mysql> exit
Bye

注意事项:

​ MySql5.7.18之后版本不再提供my.cnf 配置文件

本站文章基于国际协议BY-NA-SA 4.0协议共享;
如未特殊说明,本站文章皆为原创文章,请规范转载。

0