--1、创建用户组mysql,创建用户mysql并将其添加到用户组mysql中,并赋予读写权限
groupadd mysql --创建mysql用户组组
useradd -r -g mysql mysql --创建mysql用户并添加到mysql用户组中
chown -R mysql mysql/ --将mysql目录访问权限赋为myql用户
chgrp -R mysql mysql/ --改变mysql目录的用户组属于mysql组
--2、创建安装目录
mkdir -p /oracle/app/mysql/data
chown -R mysql.mysql /oracle/app/mysql
--3、上传MySQL文件并进行解压
cd /oracle/app/mysql
mv /software/V974639-01.zip .
unzip V974639-01.zip
tar zxf mysql-advanced-5.7.21-el7-x86_64.tar.gz
--4、创建配置文件,保存并退出
vim /etc/my.cnf
[client]
port = 3307
socket = /oracle/app/mysql/data/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/oracle/app/mysql
datadir=/oracle/app/mysql/data
socket=/oracle/app/mysql/data/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
--5、初始化数据库
--创建日志文件
cd /var/log/
vim mysqld.log
:wq
chmod 777 mysqld.log
chown mysql:mysql mysqld.log
--初始化数据库
/oracle/app/mysql/bin/mysqld --initialize --user=mysql --basedir=/oracle/app/mysql --datadir=/oracle/app/mysql/data --lc_messages_dir=/oracle/app/mysql/share --lc_messages=en_US
注:需要安装一下libaio
yum install libaio
--6、查看初始化密码
cat /var/log/mysqld.log
最后一行:root@localhost: 这里就是初始密码
root@localhost: A8#OH=pkfSf5
--7、启动MySQL服务,修改初始密码,运行远程连接测试
/oracle/app/mysql/support-files/mysql.server start
set password=password('mysql5.7');
flush privileges;
UPDATE `mysql`.`user` SET `Host` = '%', `User` = 'root' WHERE (`Host` = 'localhost') AND (`User` = 'root');
#然后执行如下操作开启mysql服务,以及设置相关权限
cd /oracle/app/mysql/data
vim mysqld.pid
chmod 777 mysqld.pid
chown mysql:mysql mysqld.pid
/oracle/app/mysql/support-files/mysql.server start
/oracle/app/mysql/bin/mysql -uroot -p 你在上面看到的初始密码
# 以下是进入数据库之后的sql语句
use mysql;
UPDATE `mysql`.`user` SET `Host`='%', `User`='root', `Select_priv`='Y', `Insert_priv`='Y', `Update_priv`='Y', `Delete_priv`='Y', `Create_priv`='Y', `Drop_priv`='Y', `Reload_priv`='Y', `Shutdown_priv`='Y', `Process_priv`='Y', `File_priv`='Y', `Grant_priv`='Y', `References_priv`='Y', `Index_priv`='Y', `Alter_priv`='Y', `Show_db_priv`='Y', `Super_priv`='Y', `Create_tmp_table_priv`='Y', `Lock_tables_priv`='Y', `Execute_priv`='Y', `Repl_slave_priv`='Y', `Repl_client_priv`='Y', `Create_view_priv`='Y', `Show_view_priv`='Y', `Create_routine_priv`='Y', `Alter_routine_priv`='Y', `Create_user_priv`='Y', `Event_priv`='Y', `Trigger_priv`='Y', `Create_tablespace_priv`='Y', `ssl_type`='', `ssl_cipher`='', `x509_issuer`='', `x509_subject`='', `max_questions`='0', `max_updates`='0', `max_connections`='0', `max_user_connections`='0', `plugin`='mysql_native_password', `authentication_string`='*7513FED7FEFCAD70E433ED117376D292D2D2B299', `password_expired`='N', `password_last_changed`='2018-4-12 12:41:07', `password_lifetime`=NULL, `account_locked`='N' WHERE (`User`='root');
flush privileges;
--8、开机自启动
cd /oracle/app/mysql/support-files
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
--9、使用systemctl start/stop mysqld.service 停止或启动服务
su - mysql
systemctl stop mysqld.service
systemctl start mysqld.service
注:需要输入Linux中root账户密码
--建立远程用户
grant all privileges on *.* to 'padmin'@'%' identified by 'padmin';
flush privileges;
--添加系统路径
vim /etc/profile
export PATH=/oracle/app/mysql/bin:$PATH
source /etc/profile
本文参照网络上的相关文章。