1.下载源码包
在mysql官网选择合适的版本,得到下载的url
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22.tar.gz 或者直接修改url
使用wget命令下载
cd /usr/local/src
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22.tar.gz
下载完成之后解压安装包
tar -zxvf mysql-5.7.22.tar.gz
下载boost
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar -zxvf boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/boost
进入mysql安装包
cd /usr/local/src/mysql-5.7.22
2.安装
卸载CentOS7默认携带的mariadb包
rpm -qa | grep -i mysql
rpm -qa | grep -i mariadb
卸载时,发现有依赖一起卸载掉
rpm -e mariadb-libs-5.5.56-2.el7.x86_64
rpm -e mariadb-libs-5.5.56-2.el7.x86_64 postfix-2:2.10.1-6.el7.x86_64
先安装一些依赖库
yum -y install cmake gcc gcc-c++ bison ncurses ncurses-devel
创建用户组和用户
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
源码编码编译:
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EMBEDDED_SERVER=1
编译
make && make install
cd /usr/local/mysql/
3.配置
设置权限
chown -R mysql:mysql /usr/local/mysql
添加配置文件
vi /etc/my.cnf
写入
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
port=3306
[mysql]
default-character-set=utf8
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
character-set-server=utf8
default-storage-engine=InnoDB
max_connections=512
query_cache_size=0
tmp_table_size=18M
thread_cache_size=8
myisam_max_sort_file_size=64G
myisam_sort_buffer_size=35M
key_buffer_size=25M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=256K
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=1M
innodb_buffer_pool_size=47M
innodb_log_file_size=24M
innodb_thread_concurrency=8
初始化mysql
/usr/local/mysql/bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
添加MySQL环境变量
vi /etc/profile
增加
/usr/local/mysql/bin:
刷新环境变量
source /etc/profile
设置开机自启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
启动mysql
mysqld_safe --defaults-file=/etc/my.cnf &
查看mysql进程
ps -ef | grep mysql
登陆MySQL
mysql -uroot
修改密码
SET PASSWORD = PASSWORD('123456');
退出mysql
quit;
重新登录mysql
mysql -uroot -p
输入上面设置的密码:123456
成功登录
配置远程访问
use mysql;
UPDATE user SET host = '%' WHERE user = 'root';
重启mysql
quit;
/etc/init.d/mysqld restart
使用 Navicat连接
使用 cmd 连接mysql(需安装Windows的mysql)
安装完成
版权声明:本文为qq_23033339原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。