centos安装mysql
- 创建用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
- 上传mysql二进制文件到/home
mysql-5.7.34-linux-glibc2.12-x86_64.tar
- 解压到/home/mysql目录
tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar /home/mysql
- 创建目录
cd /home/mysql
mkdir data logdir
- 修改目录权限
cd /home
chown -R mysql:mysql mysql
chmod 750 mysql
- 修改环境变量
vi /etc/profile
export PATH=/home/mysql/bin:$PATH
source /etc/profile
- 配置service支持mysqld,mysql命令
cp /home/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
cp /home/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
- 初始化数据库
mysqld --initialize-insecure --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data
- 添加并修改my.cnf
cd /etc
vi my.cnf
my.cnf文件如下
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/home/mysql
datadir=/home/mysql/data
socket=/tmp/mysql.sock
log-error=/home/mysql/logdir/mysqld.log
pid-file=/home/mysql/data/mysqld.pid
#不区分大小写
lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
-
启动mysql
service mysql start
报错:
Starting MySQL.2022-09-29T11:26:43.367099Z mysqld_safe error: log-error set to '/home/mysql/logdir/mysqld.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/home/mysql/data/mysqld.pid).
因为my.cnf配置的日志文件没有创建:
执行如下命令
```
touch /home/mysql/logdir/mysqld.log
chmod -R mysql:mysql /home/mysql
```
- 修改登录密码
mysql -uroot -p
密码为空
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'hisense';
FLUSH PRIVILEGES;
-
增加远程登录
grant all privileges on *.* to 'root'@'%' identified by 'hisense';
-
设置开机启动
chkconfig mysql on 查看是否成功 chkconfig --list | grep msyql