环境准备:
操作系统: http://vault.centos.org/6.5/isos/x86_64/ 下载 CentOS-6.5-x86_64-bin-DVD1.iso vmware workstation下安装系统
MySQL安装包连接地址: https://downloads.mysql.com/archives/community/ 下载 mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
介绍了本次安装使用的系统和软件版本,下面进行安装步骤介绍:
安装mysql之前需要确保系统中有libaio依赖,使用如下命令:
yum search libaio
yum install libaio
检查是否安装了mysql
[root@mysql-5 ~]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@mysql-5 ~]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
[root@mysql-5 ~]# find / -name mysql
[root@mysql-5 ~]#
本次通过wget方式下载到/usr/local
[root@mysql-5 local]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
[root@mysql-5 local]# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
[root@mysql-5 local]# ln -s mysql-5.7.17-linux-glibc2.5-x86_64 mysql
进入到mysql目录,可以发现,mysql5.7的版本和5.6的版本不同,没有/data目录,这里要自己创建一个data目录data目录并不限定存放位置,但是为了方便,这里依旧直接放在mysql的根目录下
[root@mysql-5 mysql]# mkdir data #如果不创建,在数据库初始化时候也是会自动创建
[root@mysql-5 mysql]# groupadd mysql #添加用户组
[root@mysql-5 mysql]# useradd -g mysql mysql -s /sbin/nologin #新建mysql用户禁止登录shell 或者使用useradd -r -g mysql mysql
扩展:
查看是否存在 mysql 组: [root@localhost ~]# more /etc/group | grep mysql
查看 msyql 属于哪个组: [root@localhost ~]# groups mysql
查看当前活跃的用户列表:[root@localhost ~]# w
[root@mysql-5 mysql]# chown -R mysql:mysql /usr/local/mysql/ #改变mysql目录权限
配置相关的启动配置文件
1、复制my_default.cnf到/etc/my.cnf (mysql启动时自动读取)
[root@mysql-5 mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
2、解决乱码问题
[root@mysql-5 mysql]# vi /etc/my.cnf
[mysql]
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character_set_server=utf8
3、复制mysql.server 到/etc/init.d/
[root@mysql-5 init.d]# cd /usr/local/mysql
[root@mysql-5 mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysql
[root@mysql-5 mysql]# vi /etc/init.d/mysql
4、修改 /etc/init.d/mysql 参数,给予2个目录位置
输入命令:vi /etc/init.d/mysql
更改:basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
5、给目录/usr/local/mysql 更改拥有者
输入命令:chown -R mysql:mysql /usr/local/mysql/
[root@mysql-5 mysql]# chown -R mysql:mysql /usr/local/mysql/
初始化mysql的数据库
1、初始化数据库
首先要去到mysql/bin目录下
老版本的命令:mysql_install_db
新版本的命令:./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
生成出一个data目录,代表数据库已经初始化成功
[root@mysql-5 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2018-12-03T03:26:22.566615Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-03T03:26:22.566682Z 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.
2018-12-03T03:26:22.566686Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-12-03T03:26:22.959606Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-03T03:26:23.015817Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-03T03:26:23.085590Z 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: 356b2873-f6ab-11e8-b3d3-000c297b7598.
2018-12-03T03:26:23.087897Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-03T03:26:23.089369Z 1 [Note] A temporary password is generated for root@localhost: aw7wEtF(.?ps
2、给数据库加密
输入命令: ./mysql_ssl_rsa-setup -datadir=/usr/local/mysql/data
3、启动mysql
输入命令:./mysqld_safe --user=mysql &
&符号:把当前进程丢给后台
进入客户端
1、 登录
输入命令:./mysql -uroot –p
然后输入你的临时密码
2、 修改密码
输入命令:set password=password('你的密码');
window远程访问Linux虚拟机的mysql
1、首先要关闭防火墙,这样window才能连接上(系统设置时候已经完成)
2、给window授权
输入命令:grant all privileges on *.* to root@'%' identified by '123456';
3、window远程连接
输入命令:mysql –hIP地址 -uroot -p123456
设置开机自动启动mysql服务
1、添加服务mysql
输入命令:chkconfig --add mysql
2、设置服务开机自启
输入命令:chkconfig mysql on
设置path环境变量
输入命令:vi /etc/profile
设置环境变量:export PATH=/usr/local/mysql/bin:$PATH
完成
这样我们的mysql5.7数据库就配置好了
参考:https://m.jb51.net/article/102621.htm
https://blog.csdn.net/debimeng/article/details/80362087