1、解压mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz包
tar -zxvf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz -C /usr/local
2、改名
mv mysql-5.7.44-linux-glibc2.12-x86_64/ mysql
3、创建数据目录data
在mysql中创建data目录,mkdir data
也可以存放在其它地方
4、创建用户
useradd -r mysql
说明:
1)-r:建一个系统帐户
2)创建用户mysql时,缺省为mysql组
3)可用id mysql查看一下。
5、给mysql目录权限
chown -R mysql:mysql mysql
-R:表示级联,
若data目录创建在其它地方也要给予权限设置
6、设置环境变量并应用
/etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
source /etc/profile
7、初始化
明确basedir、datadir位置
./bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
成功时,最后会出现临时密码,若未出现,则出错。
初始化时会出现各种各样的错误,注意看提示。
1)初次初始化错误时,再次初始化要删除掉data下的所有文件。
2)还有权限,拼写等
8、将mysql服务端加载到系统服务中
1)复制
support-files:cp mysql.server /etc/init.d/mysqld
2)重新加载系统配置
systemctl daemon-reload
提示:可通过help查看
3)启动mysql服务并验证
systemctl start mysqld
systemctl status mysqld
9、mysql客户端连服务端
注意mysql客户端位置。
mysql -uroot -p
利用临时密码连接,并修改临时密码。
思考:
1)my.cnf配置文件位置。
记录一个错误:
[root@bigdata3 support-files]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@bigdata3 support-files]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2024-03-11 16:06:45 CST; 59s ago
Docs: man:systemd-sysv-generator(8)
Process: 412 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)
Mar 11 16:06:44 bigdata3 systemd[1]: Starting LSB: start and stop MySQL...
Mar 11 16:06:44 bigdata3 mysqld[412]: Starting MySQL.Logging to '/usr/local/mysql/data/bigdata3.err'.
Mar 11 16:06:45 bigdata3 mysqld[412]: ERROR! The server quit without updating PID file (/usr/loc...id).
Mar 11 16:06:45 bigdata3 systemd[1]: mysqld.service: control process exited, code=exited status=1
Mar 11 16:06:45 bigdata3 systemd[1]: Failed to start LSB: start and stop MySQL.
Mar 11 16:06:45 bigdata3 systemd[1]: Unit mysqld.service entered failed state.
Mar 11 16:06:45 bigdata3 systemd[1]: mysqld.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
操作中未设置权限:chown -R mysql:mysql mysql