四、启动mariadb
root用户直接启动,由于我的环境是vagrant ssh连接的,默认的是vagrant用户
systemctl start mariadb #用root用户启动,非root用户需要sudo
mysql
进入mariadb:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> select * from mysql.user \G
ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for table 'user'
#这里就2个库,mysql库看不到,当然也查看不了
MariaDB [(none)]> select user();
+-------------------+
| user() |
+-------------------+
| vagrant@localhost |
+-------------------+
1 row in set (0.00 sec)
#看到 当前登录的用户是,因为刚才是mysql 直接进来的,此时我们要给mariadb配置初始密码;
mysqladmin -u root password #设置root密码。
再来,这次不直接mysql进来了
mysql -uroot -p
这里输入刚才的密码
进来了
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> select * from mysql.user \G 正常查询
忘记root密码:
systemctl stop mariadb 先关闭服务
su - root 切到系统root用户
mysqld_safe --skip-grant-tables & 跳过认证启动服务
mysql mysql进入服务
use mysql 切换到mysql库
UPDATE user SET password=password('heheda') WHERE user='root';