【Mysql】Linux安装Mysql
目录:
4、先检查是否有mysql用户组和mysql用户,没有就添加有就忽略
10、quit 退出Mysql --> 验证MySQL是否安装成功
(1)设置密码策略
(2)mysql禁止远程root登陆
(3)给某个用户授权某个数据库
(4)mysql报错:You must reset your password using ALTER USER statement before executing this statement.
rpm -qa | grep mysql
如果像上边截图那样有安装mysql,则要进行删除,使用下面的清除命令进行删除mysql【小编安装完mysql,使用查看命令依然未发现有安装mysql,目前不太清除为什么】
# xxx代表要删除的文件全名
rpm -e xxx
官网地址:https://downloads.mysql.com/archives/community/
tar -zxvf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
mv /data/software/mysql-5.7.35-linux-glibc2.12-x86_64 /usr/local/mysql
4、先检查是否有mysql用户组和mysql用户,没有就添加有就忽略
groups mysql
添加用户组和用户 groupadd mysql && useradd -r -g mysql mysql
mkdir -p /data/mysql chown mysql:mysql -R /data/mysql
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql # 初始化Mysql
bin/mysql_ssl_rsa_setup --datadir=/data/mysql # 开启ssl安全连接
注意:此处需要记录生成的临时密码,如上文结尾处的:V39Og4fzms-. 【如果没记住可以去 cat /data/mysql/mysql.err 查看临时密码】
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
vim /etc/my.cnf 输入以下代码
[mysqld]
bind-address=0.0.0.0
port=你的端口号
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
# 编码配置
character_set_server=utf8
# 密码验证插件
plugin-load-add=validate_password.so
# 服务运行过程中不可删除插件
validate-password=FORCE_PLUS_PERMANENT
# 开启Binlog日志
log_bin=mysql-binlog
server_id=1
[mysqld_safe]
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
# 免密登陆
# skip-grant-tables
# 数据行更新时,timestamp类型字段不更新为当前时间
explicit_defaults_for_timestamp=true
# Disabling symbolic-links is recommended to prevent assorted security risks
# 建议禁用符号链接,防止各类安全风险
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
Mysql启动脚本修改
vim /etc/init.d/mysql 增加以下内容:
basedir=/usr/local/mysql
datadir=/data/mysql
cd /usr/local/mysql/bin
service mysql start
# 登录mysql
mysql -hlocalhost -uroot -p
# 如果出现:-bash: mysql: command not found
# 执行:ln -s /usr/local/mysql/bin/mysql /usr/bin 【没有出现就不用执行】
# 输入第6步生成的临时密码
登录mysql成功页面
修改root密码【设置密码策略详见:https://blog.csdn.net/Ahuuua/article/details/125359010】
set global validate_password_policy=0; #修改validate_password_policy参数的值 set global validate_password_length=1; #修改密码长度参数 alter user 'root'@'%' identified by '123456'; #设置root账号的密码
# 如果mysql报错:You must reset your password using ALTER USER statement before executing this statement.
# MySQL版本5.7.6版本以前用户可以使用如下命令:SET PASSWORD = PASSWORD('123456');
# MySQL版本5.7.6版本开始的用户可以使用如下命令:ALTER USER USER() IDENTIFIED BY '123456'; grant all privileges on *.* to 'root'@'%' identified by '123456'; #设置所有远程都可以连接数据库 flush privileges; #刷新mysql的系统权限
10、quit 退出Mysql --> 验证MySQL是否安装成功
(1)打开防火墙指定端口
(2)如果用的云服务器,还需要打开指定的安全组【可参考:https://www.cnblogs.com/hwh000/p/16168668.html】
(3)使用数据库连接工具进行连接
(2)禁止mysql+root,mysql禁止远程root登陆 (转)
(4)mysql报错:You must reset your password using ALTER USER statement before executing this statement.
小编不易,安装完,可否来个三连,赏个赞也是好的呀!!!
博客参考:
Linux安装MySQL详细教程(图文教程):https://www.cnblogs.com/caoyunpu/p/16660871.html
Linux 安装Mysql 详细教程(图文教程):https://blog.csdn.net/bai_shuang/article/details/122939884