sofh7777 发表于 2019-2-16 11:45:10

centos7 安装mariadb

  centos7 安装mariadb
  一、使用国内源:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-
Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-7.repo

二、安装mariadb
yum -y install mariadb mariadb-server mariadb-devel
三、cat /etc/my.cnf

  default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8

四、启动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';
[*]flush privileges;
[*]ps -ef |grep mysql|grep -v grep |awk '{print $2}'|xargs kill -9
[*]systemctl start mariadb



页: [1]
查看完整版本: centos7 安装mariadb