mysql5.7编译安装
1. 安装库文件
安装编译代码需要的包
shell>yum -y install make gcc-c++ bisonncurses-devel #Set timezone(设置服务器的时区:亚洲上海) shell>rm -rf /etc/localtime shell>ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#Remove MYSQL if exists mysql (删除服务器上已存在MYSQL,切记数据库备份) shell>rpm -qa|grep mysql shell>rpm -e mysql shell>yum -y remove mysql-server mysql mysql-libs |
2. 下载编译安装cmake
cmake-2.8.4.tar.gz,cmake安装包.在www.cmake.org可下最新版本
Shell>tar -zxvf cmake-2.8.8.tar.gz shell>cd cmake-2.8.8 shell>./bootstrap shell>make shell>make install |
3. 下载安装boost
(MySQL currently requires boost_1_59_0),http://sourceforge.net/projects/boost/files/boost/
shell>unzipboost_1_59_0.zip shell>mvboost_1_59_0 /usr/local/boost shell>cd /usr/local/boost shell> ./bootstrap.sh shell> ./b2 |
4. 编译安装Mysql 5.7.9版本
shell>tar zxvf mysql-5.7.9.tar.gz shell>cd mysql-5.7.9 shell>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_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_EXAMPLE_STORAGE_ENGINE=0 -DWITH_FEDERATED_STORAGE_ENGINE=0 -DWITH_BOOST=/usr/local/boost -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=1 -DWITH_EXTRA_CHARSETS=gbk,gb2312,utf8,ascii,utf8mb4 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
shell>make -j`grep processor /proc/cpuinfo | wc -l` && make install |
5. 配置MySQL用户
shell>groupadd mysql shell>useradd -g mysql -s /sbin/nologin mysql |
修改权限
shell>chown -R mysql.mysql /usr/local/mysql shell>mkdir /var/lib/mysql shell>chown -R mysql.mysql /var/lib/mysql #socket文件存放位置 |
6. 初始化mysql数据库
进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表
shell> bin/mysql_install_db --user=mysql # Before MySQL 5.7.6 shell> bin/mysqld --initialize --user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data # MySQL 5.7.6 and up
2015-10-25T13:55:17.985338Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2015-10-25T13:55:20.481855Z 0 [Warning] InnoDB: New log files created, LSN=45790 2015-10-25T13:55:20.757621Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2015-10-25T13:55:20.829606Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0803aa28-7b20-11e5-9937-000c29502ea3. 2015-10-25T13:55:20.831561Z 0 [Warning] Gtid table is not ready to be used. Table "mysql.gtid_executed" cannot be opened. 2015-10-25T13:55:20.844288Z 1 [Note] A temporary password is generated forroot@localhost: 8QVlQ(s82//L |
7. 修改my.cnf配置文件(自由发挥)
shell>vi /etc/my.cnf [mysqld] # These are commonly set, remove the # and set as required. basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=3306 #server_id = ..... socket=/var/lib/mysql/mysql.sock |
8. 添加mysql自启动
添加服务,拷贝服务脚本到init.d目录,并设置开机启动
shell>cp support-files/mysql.server /etc/init.d/mysqld shell>chkconfig mysqld on shell>service mysqld start |
9. 配置环境变量
MySQL启动成功后,root默认没有密码,我们需要设置root密码。
设置之前,我们需要先设置PATH,使之直接调用mysql
修改/etc/profile文件,在文件末尾添加
#vi /etc/profile PATH=/usr/local/mysql/bin:$PATH export PATH |
关闭文件,运行下面的命令,让配置立即生效
#source /etc/profile |
10. 新添加的初始化密码
mysql5.7会生成一个初始化密码
shell>mysql -uroot -p’eZ4hXJ,r2Tde’ mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 修改默认密码 mysql>alter user "root"@"localhost" identified by "123456"; |
11. 添加防火墙
防火墙的3306端口默认没有开启,若要远程访问,需要开启这个端口
打开/etc/sysconfig/iptables
在“-A INPUT –m state--state NEW –m tcp –p –dport 22 –j ACCEPT”,下添加:
-A INPUT-m state --state NEW -m tcp -p -dport 3306 -j ACCEPT
然后保存,并关闭该文件,在终端内运行下面的命令,刷新防火墙配置:
serviceiptables restartCentOS 7中默认使用Firewalld做防火墙,所以修改iptables后,在重启系统后,根本不管用。
Firewalld中添加端口方法如下:
firewall-cmd--zone=public --add-port=3306/tcp --permanent
firewall-cmd--reload
有做软件测试的小伙伴们可以一起学习,进Q群 339614248
- 上一篇: MYSQL实践心得:table_open_cache的设置
- 下一篇: Python标准输出重定向