下载mysql :
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
切换到root用户
解压mysql压缩包
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
将解压后的文件夹移动到/usr/local下并重命名
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/
mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
添加用户组
groupadd mysql
添加用户mysql 到用户组mysql(使用-r参数表示mysql用户是一个系统用户,不能登录)
useradd -r -g mysql mysql
添加完用下面命令测试,能看到mysql用户的信息
id mysql
手动创建MySQL data目录
mkdir /usr/local/mysql/data/
将mysql及其下所有的目录所有者和组均设为mysql
chown -R mysql:mysql /usr/local/mysql/
新建my.cnf文件,文件路径为/etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
init-connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
max_connections=50
character-set-server=utf8
default-storage-engine=INNODB
添加执行权限,可不做配置
chmod +x /usr/local/mysql/bin/*
配置环境变量,可不做配置
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
初始化mysql,默认没有密码
cd /usr/local/mysql
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
修改mysql相关文件夹权限
chown -R root:root /usr/local/mysql/
chown -R mysql:mysql /usr/local/mysql/data/
启动mysql
cd /usr/local/mysql/support-files
./mysql.server start
#此命令也可启动
#bin/mysqld_safe --user=mysql &
修改密码
cd /usr/local/mysql/bin
./mysql -u root -p # 默认没有密码,直接敲回车就可以
use mysql;
update user set authentication_string=password('密码') where user='root';
flush privileges;
exit;
测试登录
cd /usr/local/mysql/bin/
./mysql -uroot -p#输入上一步设置的密码,紧跟着-p
show databases;
exit; #退出
设置外网可以访问
cd /usr/local/mysql/bin/
./mysql -uroot -p#输入上一步设置的密码,紧跟着-p
use mysql;
select host,user from user;
#可以看到user为root,host为localhost的话,
#说明mysql只允许本机连接,那么外网,本地软件客户端就无法连接了。
#调整方法:
update user set host='%' where user ='root';
flush privileges;
mysql服务的启动和停止命令
cd /usr/local/mysql/support-files
#查看状态
./mysql.server status
#启动
./mysql.server start
#关闭
./mysql.server stop
来源链接:https://www.jianshu.com/p/7744856185b3
标签:bin,root,mysql5.7,Linux,离线,usr,mysql,local,user From: https://www.cnblogs.com/fxcoding/p/17174944.html