wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql/
cd /usr/local
mv mysql-5.7.36-linux-glibc2.12-x86_64 mysql
mkdir mysql/data
chmod -R 777 /usr/local/mysql/data
groupadd mysql
useradd -g mysql mysql
vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
pid-file=/usr/local/mysql/data/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql/
yum -y install libaio-devel.x86_64
yum -y install numactl
cat /usr/local/mysql/data/mysql.err
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql start
./mysql -h localhost -u root -p
set password=password('rootxjhy');
flush privileges;
use mysql;
update user set Host='%' where User='root';
flush privileges;
firewall-cmd --query-port=3306/tcp
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --query-port=3306/tcp
腾讯云服务器端口怎么开放?端口开通教程
腾讯云服务器端口怎么开放?端口开通教程 - 腾讯云开发者社区-腾讯云
阿里云添加安全组规则
添加安全组规则_云服务器 ECS-阿里云帮助中心
CREATE USER 'xjhy'@'%' IDENTIFIED BY 'xjhy';
SELECT host,user FROM mysql.user WHERE user='xjhy';
以下是一些MySQL用户常用的权限:
ALL: 所有可用的权限
CREATE: 创建库、表和索引
LOCK_TABLES: 锁定表
ALTER: 修改表
DELETE: 删除表
INSERT: 插入表或列
SELECT: 检索表或列的数据
CREATE_VIEW: 创建视图
SHOW_DATABASES: 列出数据库
DROP: 删除库、表和视图
一般都是给到业务数据库权限,不要给删除库、表和视图的权限,核心库mysql数据库的权限也不要给,根据自己的需求来。root用户赋予所有权限使用如下命令:
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ WITH GRANT OPTION;
flush privileges;
我只给了业务库(zhy)除删除库、表和视图的其它权限,核心库(information_schema、performance_schema、mysql)的查看权限。
GRANT PROCESS ON *.* TO 'xjhy'@'%';
GRANT SELECT ON `information_schema`.* TO 'xjhy'@'%';
GRANT SELECT ON `performance_schema`.* TO 'xjhy'@'%';
GRANT SELECT ON `mysql`.* TO 'xjhy'@'%';
GRANT CREATE,ALTER,INSERT,SELECT,DELETE,UPDATE,INDEX ON `zhy`.* TO 'xjhy'@'%';
flush privileges;
使用远程连接Navicat工具等可能会报错:1227 - Access denied; you need (at least one of) the PROCESs privilege(s) for this operation
这是因为PROCESS权限是用来查看谁连接数据的一个权限,除了root用户,都只能看到自己的。使用如下命令赋权解决
GRANT PROCESS ON *.* TO 'xjhy'@'%';
flush privileges;