下载MySQL源码包
目前MySQL5.7最新版本是5.7.24,到官网下载
https://dev.mysql.com/downloads/mysql/5.7.html
这里操作系统选择Source Code,系统版本选择Generic Linux(Architecture Independent)
Compressed TAR Archive Compressed TAR Archive, Includes Boost Headers 两个版本都可以,includes Bosst也是需要添加下载boost参数.
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.24.tar.gz
安装依赖
根据官方的安装引导,编译需要安装CMake,make,gcc,ncurses library等依赖,因为之前安装过,没法测试是否完整.
yum install -y cmake make gcc gcc-c++ ncurses ncurses-devel
接下来就开始编译安装了
编译安装
还是先看官方文档:
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysqlshell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> mkdir bld
shell> cd bld
shell> cmake ..
shell> make
shell> make installshell> cd /usr/local/mysql
shell> scripts/mysql_install_db --user=mysql
shell> bin/mysqld_safe --user=mysql &shell> cp support-files/mysql.server /etc/init.d/mysql.server
实际安装过程中有些不同,有些地方需要添加参数,有些命令已经过时
# 安装前的设置
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
# 开始编译安装
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> mkdir bld
shell> cd bld
shell> cmake .. -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
# 网上的有些别的参数和默认参数一致就没有使用
shell> make
# 编译用了很长时间,接近8个小时
shell> make install
shell> cd /usr/local/mysql
shell> bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --explicit_defaults_for_timestamp
# --initialize-insecure不生成密码 --initialize生成随机密码可以在日志中查看
shell> cp support-files/mysql.server /etc/init.d/mysql.server
# 将MySQL服务文件拷贝
shell> echo "export PATH=$PATH:/home/mysql/bin">>/etc/profile
shell> source /etc/profile
# 添加环境变量
设置开机启动
shell> chkconfig --add mysql.server
shell> chkconfig mysql.server on
shell> chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysql.server 0:off 1:off 2:on 3:on 4:on 5:on 6:off
启动MySQL
shell> systemctl start mysql.server
shell> systemctl status mysql.server
# 查看是否启动成功
创建用户以及修改用户权限
-
登录修改root密码
shell> mysql -uroot -p # 输入日志中的随机密码 mysql> set password=password('123456');
-
创建用户用于外部访问
mysql> create user 'username'@'%' identified by 'password'; # 创建可以外部访问的新用户 mysql> grant all privileges on *.* to 'username'@'%' identified by 'password' with grant option; mysql> grant select,insert,update,delete on *.* to 'username'@'%' identified by 'password' with grant option; # 赋予权限 mysql> flush privileges; # 写入权限
防火墙设置
创建了可以外部访问的用户,但还是连接不上,这是因为centos的防火墙没有添加3306的端口
shell> firewall-cmd --permanent --add-port=3306/tcp
# 添加--permanent可以永久启用
shell> firewall-cmd --reload
# 光设置还不行,需要让防火墙重新载入.
编译安装完成!
网友评论