Centos服务器非root用户mysql安装

1、使用yum安装numactl,后续mysqld需要用到
yum -y install numactl

2、创建mysql用户:
groupadd mysql;useradd -g mysql -d /opt/mysql mysql #创建mysql组、mysql用户
passwd mysql #修改用户密码

3、mysql用户登录,创建mysql的数据、配置、日志路径:
mkdir -p /opt/mysql/data
mkdir -p /opt/mysql/etc
mkdir -p /opt/mysql/logs

4.登录mysql官网https://dev.mysql.com/downloads/mysql/ 下载mysql-5.7.23-el7-x86_64.tar.gz安装tar包
将其上传到服务器的mysql用户的/opt/mysql目录下,解压tar包:
tar xzvf mysql-5.7.23-el7-x86_64.tar.gz
cd mysql-5.7.23-el7-x86_64; mv * /opt/mysql

5、初始化数据库
mysqld --initialize --user=installadmin --basedir=/opt/mysql --datadir=/opt/mysql/data/ --lc_messages_dir=/opt/mysql/share --lc_messages=en_US

6、编辑/etc/my.cnf文件,以下是示例:
$ cat /etc/my.cnf
[mysqld]
port = 3306
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
basedir=/opt/mysql
collation_server = utf8_general_ci
character_set_server = utf8
pid-file = /opt/mysql/data/mysql.pid
user = mysql

[mysqld_safe]
log-error=/opt/mysql/logs/mysql_error.log
pid-file=/opt/mysql/logs/mysql.pid

修改其属主为mysql,便于后期维护:
chown mysql:mysql /etc/my.cnf

分配权限
sudo chown -R app:app /opt

在logs文件夹下建日志文件
touch mysql_error.log

启动数据库:
mysqld –user=mysql –basedir=/opt/mysql –datadir=/opt/mysql/data > /opt/mysql/logs/start.log 2>&1 &
或者
./bin/mysqld_safe --defaults-file=/etc/my.cnf &

mysql -uroot -P6603(端口号) -p
修改初始密码:
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘new_password’;

use mysql;
查看用户状态:
select user, host from user;

grant all privileges on . to ‘root’@’%’ identified by ‘root’ with grant option;

flush privileges;

你可能感兴趣的:(Linux工具安装)