Centos7安装部署mysql (tar.gz)

目录

一、查看是否安装

二、安装


一、查看是否安装

rpm -qa|grep -i mysql

若有则通过一下命令删除卸

sudo rpm -ev --nodeps mysql-community-server-5.6.51-2.el7.x86_64

sudo rpm -ev --nodeps mysql-xxxxxxxxx

二、安装

1、下载tar.gz包

2、将其放到 /opt/module

3、解压到当前文件夹

4、将当前解压后的mysql

mv mysql.xxxxxx /usr/local/mysql

5、在以下目录下新建mysql.sock文件,并赋予chmod 777 权限

cd /usr/local/mysql

sudo touch mysql.sock

6、配置环境变量

(1)mysql.sock

配置mysql-config

cd /usr/local/mysql/bin

sudo vim ./mysql_config

修改mysql.sock文件的路径

配置mysql的环境变量

sudo vim /etc/profile

export MYSQL_HOME=/usr/local/mysql

export PATH=$MYSQL_HOME/bin:$PATH

source /etc/profile

配置/etc/my.cnf

[mysqld]
datadir=/usr/local/mysql
socket=/usr/local/mysql/mysql.sock
# 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 http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/usr/local/mysql/log/localhost.localdomain.log
pid-file=/usr/local/mysql/pid/localhost.localdomain.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

不然会出现以下错误

[root@localhost mysql]# ./support-files/mysql.server start
Starting MySQL.2023-08-21T02:27:19.826210Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

7、cd ../ (/usr/local/mysql)

8、为centos添加mysql用户组和mysql用户(-s /bin/false参数指定mysql用户仅拥有所有权,而没有登录权限):

groupadd mysql

useradd-r -g mysql -s /bin/false mysql

9、进入安装mysql软件的目录,命令如下:

cd /usr/local/mysql

10、修改当前目录拥有者为新建的mysql用户,命令如下:(有时需要赋予root权限)

chown -R mysql:mysql ./

11、安装mysql,命令如下:(有时需要赋予root权限)

./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

安装完成,出现如下信息,将随机生成的登录密码记录下来:

12、开启mysql服务,命令如下:

./support-files/mysql.server start

13、将mysql进程放入系统进程中,命令如下:

cp support-files/mysql.server /etc/init.d/mysqld

14、重新启动mysql服务,命令如下:

service mysqld restart

15、使用随机密码登录mysql数据库,命令如下:

mysql -u root -p

等待系统提示,输入随机密码,即可登录

16、进入mysql操作行,为root用户设置新密码(小编设为rootroot):

alter user ‘root‘@‘localhost‘ identified by ‘rootroot‘;

alter user ‘root‘@‘localhost‘ identified by ‘password‘;

17、设置允许远程连接数据库,命令如下:

use mysql;

update user set user.Host=‘%‘ where user.User=‘root‘;

18、刷新权限,命令如下:

flush privileges;

你可能感兴趣的:(mysql,adb,数据库)