前言
有朋友问怎么编译安装mysql5.7版本,所以趁今天分享下之前在ubuntu14.04系统编译安装的过程,希望对大家有点帮助。
环境:
服务器关闭防火墙,外部访问mysql,或者开通3306端口
root@ubuntu:~# ufw disableFirewall stopped and disabled on system startup
1、创建服务启动用户,解压并移动到安装位置
安装包地址:/opt/mysql/mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
1.1 解压安装mysql
#tar -xvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz -C /usr/local
root@ubuntu:/usr/local/mysql# lltotal 60drwxr-xr-x 9 root root 4096 Nov 8 22:53 ./drwxr-xr-x 16 root root 4096 Nov 8 22:48 ../drwxr-xr-x 2 root root 4096 Nov 8 22:51 bin/-rw-r--r-- 1 7161 31415 17987 Sep 28 2016 COPYINGdrwxr-xr-x 2 root root 4096 Nov 8 22:52 docs/drwxr-xr-x 3 root root 4096 Nov 8 22:50 include/drwxr-xr-x 5 root root 4096 Nov 8 22:52 lib/drwxr-xr-x 4 root root 4096 Nov 8 22:51 man/-rw-r--r-- 1 7161 31415 2478 Sep 28 2016 READMEdrwxr-xr-x 28 root root 4096 Nov 8 22:52 share/drwxr-xr-x 2 root root 4096 Nov 8 22:52 support-files/root@ubuntu:/usr/local/mysql# pwd/usr/local/mysql
1.2 创建服务启动用户
#groupadd mysql#useradd -r -g mysql -s /bin/bash mysql -d /home/mysql -m
1.3 设置文件权限
#chown -R mysql:mysql /usr/local/mysql
2.mysql文件相关配置
2.1 设置mysql服务启动脚本
2.1.1 添加mysql为系统服务
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#vi /etc/init.d/mysqld
basedir=/usr/local/mysqldatadir=/usr/local/mysql/data
2.1.2 授权mysql系统服务
#chmod 755 /etc/init.d/mysqld
配置后可通过service mysqld start 启动mysql服务
2.2 修改mysql配置文件my.cnf
#cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
(查看support-files目录下是否有mysql-medium.cnf文件,有的话直接复制)
#vi /etc/my.cnf
[mysqld]#socket = /usr/local/mysql/data/mysql.sockbasedir = /usr/local/mysqldatadir = /usr/local/mysql/datamax_allowed_packet=50Mlower_case_table_names=0character_set_server = utf8# Remove leading # to set options mainly useful for reporting servers.# The server defaults are faster for transactions and fast SELECTs.# Adjust sizes as needed, experiment to find the optimal values.# join_buffer_size = 128M# sort_buffer_size = 2M# read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
2.3 添加mysql为系统变量
#vi /etc/profile ==>添加PATH=$PATH:MYSQL安装包路径/bin
export PATH=$PATH:/usr/local/mysql/bin
#source /etc/profile //使文件生效
#echo $PATH //查看是否加入成功
root@ubuntu:/usr/local/mysql# echo $PATH/usr/local/jdk1.8.0_131/bin:/home/zookeeper-3.4.9//bin:/usr/local/jdk1.8.0_131/bin:/home/zookeeper-3.4.9//bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/mysql/bin
3.mysql数据库配置
3.1 安装mysql数据库(mysql用户)
初始化生成基础库(需把之前的/data文件删除)
#./bin/mysqld --initialize
mysql@ubuntu:/usr/local/mysql$ ./bin/mysqld --initialize2017-11-09T07:38:38.745575Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2017-11-09T07:38:38.745823Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)2017-11-09T07:38:38.746638Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2017-11-09T07:38:38.746665Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.2017-11-09T07:38:38.746672Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.2017-11-09T07:38:40.095496Z 0 [Warning] InnoDB: New log files created, LSN=457902017-11-09T07:38:40.573958Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2017-11-09T07:38:40.815986Z 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: 0184c08c-c521-11e7-84c6-000c291e3617.2017-11-09T07:38:40.840897Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2017-11-09T07:38:40.884876Z 1 [Note] A temporary password is generated for root@localhost: k%T3TJt7&(gm
其中k%T3TJt7&(gm 为mysql初始密码
3.2 授权数据库文件
/usr/local/mysql/data存放数据库文件
# chown -R mysql:mysql /usr/local/mysql/data/
4、mysql数据库相关设置
4.1 启动mysql数据库
4.1.1 启动服务
#service mysqld start
[root@localhost etc]# service mysqld start Starting MySQL. [确定]
4.1.2 连接MYSQL
#mysql -u root -p
root@ubuntu:/usr/local/mysql/bin# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 4Server version: 5.7.16Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.mysql> use mysql;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected, 1 warning (0.14 sec)mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql>
4.2 设置mysql连接权限
查询mysql连接用户情况:
select host,user from user;
设置远程:
UPDATE user SET Host='%' WHERE User='root' AND Host='localhost'
设置本地连接权限
UPDATE user SET Host='localhost' WHERE User='root' AND Host='127.0.0.1'
grant 授权远程
grant all privileges on *.* to root@'%' identified by '123456' with grant option;
后面会更多专注分享DBA方面的内容,感兴趣的朋友可以关注下!!