Linux 搭建mysql环境
Posted Adorable_Rocy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 搭建mysql环境相关的知识,希望对你有一定的参考价值。
首先准备安装包
链接:https://pan.baidu.com/s/1n27P4uveIAdVEh0tlrTduA
提取码:8509
-
解压文件到 /usr/local/mysql 下
-
在mysql目录中创建data目录
-
查看组名和添加组名
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql
# 创建组名
groupadd mysql
useradd -r -g mysql mysql
# 修改mysql所有组
chown -R mysql.mysql /usr/local/mysql/mysql
# 添加权限
chmod u+x *
- 配置/etc/my.cnf配置文件
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /usr/local/mysql/mysql
datadir = /usr/local/mysql/mysql/data
port = 3307
socket = /tmp/mysql.sock
character-set-server=utf8
log-error = /usr/local/mysql/mysql/data/mysqld.log
pid-file = /usr/local/mysql/mysql/data/mysqld.pid
- 初始化
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql/ --datadir=/usr/local/mysql/mysql/data/
- 查看初始密码
cat /usr/local/mysql/mysql/data/mysqld.log
2022-04-13T10:54:04.370436Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-04-13T10:54:04.370670Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
...
2022-04-13T10:54:08.811937Z 1 [Note] A temporary
password is generated for root@localhost: W9h,mzx>Eepw
- 复制脚本到目录中
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
- 启动服务并且登录
[root@localhost mysql]# service mysql start
[root@localhost mysql]# ./bin/mysql -u root -p
#修改密码
set password=password('root');
#设置可以远程访问
grant all privileges on *.* to root@'%' identified by 'root';
#刷新权限
flush privileges;
#重启服务器
service mysql restart
随后正常登录完毕
以上是关于Linux 搭建mysql环境的主要内容,如果未能解决你的问题,请参考以下文章