赞
踩
mysql 数据目录初始化及服务启动阶段依赖libaio
,检测是否已安装libaio
dnf install libaio
## 创建用户组
groupadd mysql
## 创建用户
useradd -r -g mysql -s /bin/false mysql
## 解压安装包
tar xvf /path/to/mysql-VERSION-OS.tar.xz -C /mysql/install/path
## 创建符号链接
ln -s full-path-to-mysql-VERSION-OS mysql
cd /opt/mysql
mkdir mysql-files
chown mysql:mysql mysql-files
# 初始化数据目录,注意生成的随机密码
bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/mysql-files
可以将basedir
,datadir
加到配置文件中 Using Option Files
# 跳转到安装目录后
# 注意:如果没有在配置文件中指定basedir,datadir 则需要在命令行中指定
bin/mysqld_safe --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/mysql-files &
使用root登陆并修改密码
[jxxchallenger@fedora-36 mysql]$ bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.3.0
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
Query OK, 0 rows affected (0.02 sec)
mysql>
手动关闭mysql
[root@fedora-36 mysql]# bin/mysqladmin -u root -p shutdown
Enter password:
2024-03-02T14:25:07.972096Z mysqld_safe mysqld from pid file /opt/mysql/mysql-files/fedora-36.pid ended
[1]+ 已完成 bin/mysqld_safe --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/mysql-files
注意此处的 -u root
指定的是用户表中的root
mysql 安装包中提供一个方便的脚本来启动/停止mysqld进程 (support-files/mysql.server
)
语法:
[root@fedora-36 support-files]# ./mysql.server
Usage: mysql.server {start|stop|restart|reload|force-reload|status} [ MySQL server options ]
配置:
在 /etc/my. cnf
中指定basedir
和datadir
;或者直接在mysql.server
中指定
启动服务:
./mysql.server start
停止服务:
./mysql.server stop
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。