标签:有用 shu nat oca scripts -- src alt png
1.将数据库down掉
/etc/init.d/mysqld stop
2.给/opt/目录下所有受mysql用户权限
chown -R mysql.mysql /opt/*
3.启动数据库
mysqld_safe --skip-grant-tables --skip-networking &
4.进入数据库
mysql
5.初始化
mysql> flush privileges;
6.设置数据库用户权限和密码
mysql> grant all on *.* to root@'localhost' identified by '1' with grant option;
7.退出重启数据库
mysql> \q
/etc/init.d/mysqld restart
8.进入数据库查看
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)
1.down掉数据库
[root@db04 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
2.删除或改名/opt/mysql/data目录
[root@db04 opt]# cd mysql
[root@db04 mysql]# mv data date
[root@db04 mysql]# rm -fr data
3.初始化
[root@db04 scripts]# ./mysql_install_db --datadir=/opt/mysql/data --basedir=/opt/mysql --
user=mysql
[root@db04 scripts]# echo $?
0
4.授权
[root@db04 scripts]# chown -R mysql.mysql /opt/*
5.启动数据库
[root@db04 scripts]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/opt/mysql/data/db04.err'.
SUCCESS!
6.进入数据库查看
[root@db04 scripts]# mysql
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | db04 |
| root | db04 |
| | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.00 sec)
1.down掉数据库
[root@db04 scripts]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
2.启动数据库
[root@db04 scripts]# mysqld_safe --skip-grant-tables --skip-networking &
[1] 25934
[root@db04 scripts]# 191031 19:41:10 mysqld_safe Logging to '/opt/mysql/data/db04.err'.
191031 19:41:10 mysqld_safe Starting mysqld daemon with databases from /opt/mysql/data
3.进入数据库
[root@db04 scripts]# mysql
4.使用数据库
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
5.创建root用户
mysql> insert into mysql.user values ('localhost','root',PASSWORD('123'),
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'',
'',
'',
'',0,0,0,0,'mysql_native_password','','N');
6.查看用户
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)
标签:有用 shu nat oca scripts -- src alt png
原文地址:https://www.cnblogs.com/chenmiao531759321/p/11773501.html