为mysql创建用户组
[[email protected] ~]# groupadd mysql
添加mysql用户
[[email protected] ~]# useradd -r -g mysql mysql
创建目录
[[email protected] ~]# mkdir -p /kingsql/database/mysql/tmp/
[[email protected] ~]# mkdir -p /kingsql/database/mysql/log/
创建mysqld.log日志
[[email protected] ~]# touch /kingsql/database/mysql/log/mysqld.log
将安装包移动到mysql目录下
[[email protected] ~]# mv mysql8.0_kingsql.tar.gz /kingsql/database/mysql/
[[email protected] ~]# cd /kingsql/database/mysql/
修改目录所属用户
[[email protected] ~]# chown mysql:mysql -R /kingsql
解压安装包
[[email protected] mysql]# tar -zxvf mysql8.0_kingsql.tar.gz
bin/
bin/mysqlxtest
bin/mysql_tzinfo_to_sql
…………………………
执行安装指令,安装结束后会给出一个初始密码
[[email protected] mysql]# /kingsql/database/mysql/bin/mysqld --initialize --user=mysql --datadir=/kingsql/database/mysql/data --basedir=/kingsql/database/mysql
修改my.cnf,添加以下内容
[[email protected] etc]# vi /etc/my.cnf
[client]
socket = /kingsql/database/mysql/tmp/mysql.sock
[mysqld_safe]
log-error=/kingsql/database/mysql/log/mysqld.log
pid-file=/kingsql/database/mysql/mysqld.pid
[mysqld]
basedir = /kingsql/database/mysql
datadir = /kingsql/database/mysql/data
port = 3306
socket = /kingsql/database/mysql/tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
将环境变量修改写入/etc/profile
[[email protected] etc]# echo "export PATH=$PATH:/kingsql/database/mysql/bin" >> /etc/profile
刷新/etc/profile
[[email protected] etc]# source /etc/profile
mysqld_safe脚本启动MySQL服务器后继续监控其运行情况
[[email protected] ~]# mysqld_safe&
[1] 2989
[[email protected] ~]# 2018-02-05T05:24:40.919162Z mysqld_safe Logging to ‘/kingsql/database/mysql/log/mysqld.log‘.
2018-02-05T05:24:40.948708Z mysqld_safe Starting mysqld daemon with databases from /kingsql/database/mysql/data
# 获取临时密码 grep ‘temporary password‘ /var/log/mysqld.log
# 使用临时密码登录 mysql -u root -p
登录Mysql,密码为刚刚的初始密码
[[email protected] ~]# mysql -u root -p
Enter password:
# 修改root账户的密码
mysql> alter user ‘root‘@‘localhost‘ identified by ‘oracle‘;
Query OK, 0 rows affected (0.16 sec)
使用Mysql数据库
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
默认的账号的host属性都是localhost,意思是这个账号只能本地使用,如果要使用某个账号来远程登录,必须将账号的host属性值更改成%。
mysql> update user set host=‘%‘;
Query OK, 4 rows affected (0.11 sec)
Rows matched: 4 Changed: 4 Warnings: 0
刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql>
mysql> GRANT ALL ON *.* TO ‘root‘@‘%‘; # *.*代表所有表的所有字段
Query OK, 0 rows affected (0.11 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
mysql>
修改密码认证方式为mysql_native_password
mysql> ALTER USER root IDENTIFIED WITH mysql_native_password BY ‘oracle‘;
Query OK, 0 rows affected (0.11 sec)
mysql>
刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
原文地址:https://www.cnblogs.com/kawashibara/p/9315939.html