Linux安装MySQL_全网最详细

上传MySQL安装包至/usr/local目录,执行命令解压

[root@JetXi local]# tar zxf mysql-5.7.28-el7-x86_64.tar.gz

对该目录进行改名,便于配置

[root@JetXi local]# mv mysql-5.7.28-el7-x86_64 mysql

创建data目录和log目录,并创建log文件

[root@JetXi local]# mkdir mysql/data
[root@JetXi local]# mkdir mysql/log
[root@JetXi local]# touch mysql/log/mysql.log

创建mysql组和mysql用户

[root@JetXi local]# groupadd mysql
[root@JetXi local]# useradd -g mysql mysql

将MySQL安装目录所属的用户和组改为MySQL

[root@JetXi local]# chown -R mysql:mysql mysql

将MySQL安装目录的权限修改为755,即文件拥有者对其可读可写可执行,其他同组用户和组外用户对其可读可执行

[root@JetXi local]# chmod 755 mysql

拷贝mysql.server文件

[root@JetXi local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

配置该文件

[root@JetXi local]# vi /etc/init.d/mysql
   basedir=http://www.likecs.com/usr/local/mysql
   datadir=http://www.likecs.com/usr/local/mysql/data

配置/etc/my.cnf文件

[root@JetXi local]# vi /etc/my.cnf
  [mysql]
   default-character-set=utf-8
   socket=http://www.likecs.com/usr/local/mysql/mysql.sock

  [mysqld]
   basedir=http://www.likecs.com/usr/local/mysql
   datadir=http://www.likecs.com/usr/local/mysql/data
   socket=http://www.likecs.com/usr/local/mysql/mysql.sock
   port=3306
   default-storage-engine=INNODB
   # 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

  [mysqld_safe]
   log-error=http://www.likecs.com/usr/local/mysql/log/mysql.log
   pid-file=http://www.likecs.com/usr/local/mysql/mysql.pid

将MySQL添加到环境变量

[root@JetXi local]# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@JetXi local]# source /etc/profile

初始化MySQL,初始化成功输出的信息中,最后一行是MySQL的临时密码

mysqld --initialize --user=mysql --basedir=http://www.likecs.com/usr/local/mysql --datadir=http://www.likecs.com/usr/local/mysql/data
...
2021-02-19T20:41:02.054551Z 1 [Note] A temporary password is generated for           root@localhost: BUcyY36C3L;<

启动MySQL服务

[root@JetXi local]# service mysql start

使用初始化生成的密码登录MySQL,登录成功说明配置成功

[root@JetXi ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzpwyf.html