下载地址
通过命令下载:wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
1、安装依赖包
libaio-devel-0.3.109-13.el7.x86_64.rpm
libaio-0.3.109-13.el7.x86_64.rpm
numactl-2.0.9-7.el7.x86_64.rpm
2、解压
#解压
tar -zxvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
#复制解压后的mysql目录
cp -r mysql-5.7.27-linux-glibc2.12-x86_64 /usr/local/mysql
或
mv mysql-5.7.27-linux-glibc2.12-x86_64 mysql
3、添加用户组和用户
#添加用户组
groupadd mysql
#添加用户mysql 到用户组mysql
useradd -g mysql mysql
4、安装
cd /usr/local/mysql/
mkdir -p ./data/mysql
chown -R mysql:mysql ./
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/mysql --initialize
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
#cp support-files/my-default.cnf /etc/my.cnf 检查/etc下是否有my.cnf 如果没有可以新建一个
#修改配置文件my.cnf
vim my.cnf
[mysqld]
datadir=/usr/local/mysql/data/mysql
socket=/tmp/mysql.sock
symbolic-links=0
[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
#修改启动脚本
vi /etc/init.d/mysqld
#修改项:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql
#设置开机启动
chmod +x /etc/init.d/mysqld
chkconfig --level 35 mysqld on
chkconfig --list mysqld
chkconfig --add mysqld
chkconfig --list mysqld
#测试启动服务
service mysqld start
#测试连接
./mysql/bin/mysql -uroot
#加入环境变量,编辑 /etc/profile,这样可以在任何地方用mysql命令了
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
#启动mysql
service mysqld start
#关闭mysql
service mysqld stop
#查看运行状态
service mysqld status
#设置密码
1、vim /etc/my.cnf
在[mysqld]下加上 skip-grant-tables
例如:
[mysqld]
datadir=/usr/local/mysql/data/mysql
socket=/tmp/mysql.sock
skip-grant-tables
2、重启mysql
3、重新登陆mysql后就可以修改密码了
4、执行下列sql
mysql -u root - p
update mysql.user set authentication_string=PASSWORD(‘test1234!@#$’) where User=‘root’;
flush privileges;
5、修改完密码将my.cnf 中的skip-grant-tables 注释掉,重启MySQL 即可
6、创建用户
create user ‘test_db’@’%’ identified by ‘test_db1234!@#$’;
7、允许远程连接
方式一、
use mysql;
select ‘host’ from user where user=‘root’;
update user set host = ‘%’ where user =‘root’;
flush privileges;
方式二:直接授权 允许任意IP 通过root用户登录数据库
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘root1234!@#
′
W
I
T
H
G
R
A
N
T
O
P
T
I
O
N
;
G
R
A
N
T
A
L
L
P
R
I
V
I
L
E
G
E
S
O
N
∗
.
∗
T
O
′
t
e
s
t
d
b
′
@
′
' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'test_db'@'%' IDENTIFIED BY 'test_db1234!@#
′WITHGRANTOPTION;GRANTALLPRIVILEGESON∗.∗TO′testdb′@′’ WITH GRANT OPTION;
flush privileges;
错误解决办法:
问题---- You must reset your password using ALTER USER statement before executing this statement
解决办法—
alter user ‘root’@‘localhost’ identified by ‘wp1234!@#$’;