1、下载官方安装包
mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
官方链接 https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
2、在/usr/local目录下创建mysql文件夹
mkdir mysql
3、上传mysql安装包,这里可以采用FTP进行上传。上传位置为/usr/local/mysql
4、解压安装包
tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
5、卸载自带的maraidb-lib-版本号
rpm -qa|grep mariadb
mariadb-libs-版本号
rpm -e --nodeps mariadb-libs-版本号
rpm -qa|grep mariadb
若卸载不了可使用 yum remove 包名 -y 命令
6、安装mysql-community-common-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
7、安装mysql-community-libs-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
8、安装mysql-community-client-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
9、安装libaio
yum install libaio
执行后按照提示输入 y
10、安装mysql-community-server-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
11、修改数据库目录
vim /etc/my.cnf
11、初始化数据库
mysqld --initialize --user=mysql
12、修改临时密码
Mysql5.7默认安装之后root是有密码的。
获取MySQL的临时密码
为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log。
只有启动过一次mysql才可以查看临时密码
grep 'temporary password' /var/log/mysqld.log
13、帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称”%”,修改root密码
mysql -u root -pvmware
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>update user set authentication_string=password('123456') where user='root';
mysql>flush privileges;
mysql>select host, user from user
跳过密码
vim /etc/my.cnf mysqld下面添加一行代码:skip-grant-tables
修改数据存放路径
MySQL安装后默认安装在/var/lib/mysql
目录下
配置文件为/etc/my.cnf
根据场景,需要将/var/lib/mysql
移动到/home/data/mysql
停止mysql服务
systemctl stop mysqld
2、创建新目录
mkdir /home/data/mysql
3、移动数据
mv /var/lib/mysql/* /home/data/mysql/
4、修改新路径owner
chown mysql:mysql -R /home/data/mysql/
5、修改配置文件/etc/my.cnf
[mysqld]
...
datadir=/home/data/mysql
socket=/home/data/mysql/mysql.sock
[client]
...
# 不增加这一行,服务可以启动,本地可以连接,但navicat连接不了
socket=/home/data/mysql/mysql.sock
6、启动数据库
[root@master data]# systemctl start mysqld
常用命令
1.启动命令
[root@xufeng Desktop]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
2.关闭命令
[root@xufeng ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
3.重启命令
[root@xufeng ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
4.查看服务状态
[root@xufeng ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2018-07-18 22:34:06 EDT; 1min 11s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4366 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 4345 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4370 (mysqld)
CGroup: /system.slice/mysqld.service
└─4370 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Jul 18 22:34:04 xufeng.goertek.com systemd[1]: Starting MySQL Server...
Jul 18 22:34:06 xufeng.goertek.com systemd[1]: Started MySQL Server.
5.查看MySql系统配置
[root@xufeng ~]# cat /etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# 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
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid