查看系统版本
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
| [root@VM_0_15_centos ~] mariadb-libs-5.5.56-2.el7.x86_64
rpm -e
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
| cd /usr/local/src
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
|
编译安装
添加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
| /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql
|
启动MySql
1 2 3 4
| /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 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 配置文件