zl程序教程

您现在的位置是:首页 >  后端

当前栏目

记录一次奇葩的mariadb不能启动解决方法:

方法 解决 启动 记录 不能 一次 MariaDB 奇葩
2023-09-11 14:22:20 时间

一、先是不能启动服务:

  错误提示大概: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 #关闭自启动

四、解决只能root用户使用mysql命令的方法:
  1、su 切换到超级用户,记得输入root密码
  2、mysql   登陆数据库
  3、见下面内容:
 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)]>