一、先是不能啟動服務:
錯誤提示大概:ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
1、關閉mysql數據庫服務
systemctl stop mysqld
2、屏蔽權限
mysqld_safe --skip-grant-table
3、新開起一個終端輸入:
mysql -u root mysql
delete from user where USER='';
FLUSH PRIVILEGES;//記得要這句話,否則如果關閉先前的終端,又會出現原來的錯誤
exit
二、重新啟動系統后,啟動過程
1、開啟mysql數據庫服務 systemctl start mysqld
2、登陸mysql, mysql -u root -p 提示ERROR 1698 (28000): Access denied for user 'root'@'localhost'
3、繼續忽略權限:mysqld_safe --skip-grant-table
4、超級用戶登陸mysql:sudo mysql -u root -p
輸入密碼:用戶密碼
輸入密碼:mysql root密碼:
三、添加自己啟動:
下次開機的時候記得啟動服務,要不然會報錯:
systemctl start mariadb
當然也可以開機自啟動.但是我覺得自己啟動比較舒服:
systemctl enable mariadb #自啟動
systemctl disable mariadb #關閉自啟動
1 MariaDB [(none)]> use mysql; 2 Reading table information for completion of table and column names 3 You can turn off this feature to get a quicker startup with -A 4 5 Database changed 6 MariaDB [mysql]> show tables; 7 +---------------------------+ 8 | Tables_in_mysql | 9 +---------------------------+ 10 | column_stats | 11 | columns_priv | 12 | db | 13 | event | 14 | func | 15 | general_log | 16 | global_priv | 17 | gtid_slave_pos | 18 | help_category | 19 | help_keyword | 20 | help_relation | 21 | help_topic | 22 | index_stats | 23 | innodb_index_stats | 24 | innodb_table_stats | 25 | plugin | 26 | proc | 27 | procs_priv | 28 | proxies_priv | 29 | roles_mapping | 30 | servers | 31 | slow_log | 32 | table_stats | 33 | tables_priv | 34 | time_zone | 35 | time_zone_leap_second | 36 | time_zone_name | 37 | time_zone_transition | 38 | time_zone_transition_type | 39 | transaction_registry | 40 | user | 41 +---------------------------+ 42 31 rows in set (0.001 sec) 43 44 MariaDB [mysql]> show user; 45 ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'user' at line 1 46 MariaDB [mysql]> create user 'gsc'@'%' identified by '設置的密碼'; 47 Query OK, 0 rows affected (0.056 sec) 48 49 MariaDB [mysql]> grant select on *.* to 'gsc'@'%'; 50 Query OK, 0 rows affected (0.040 sec) 51 52 MariaDB [mysql]> flush privileges; 53 Query OK, 0 rows affected (0.001 sec) 54 55 MariaDB [mysql]> exit 56 Bye 57 [developRos WORKM]# exit 58 exit 59 nication ~ WORKM mysql -ugsc -p剛設置的密碼 60 Welcome to the MariaDB monitor. Commands end with ; or \g. 61 Your MariaDB connection id is 21 62 Server version: 10.5.8-MariaDB Arch Linux 63 64 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. 65 66 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 67 68 MariaDB [(none)]>