• Docker安装MariaDB-10.2


    1 docker search mariadb 搜索mariadb镜像(非必须)

    2 docker pull mariadb 下载docker镜像

    3 docker images 查看本地已有的所有镜像

    4 mkdir -p /data/mariadb/data 建一个目录作为和容器的映射目录

    5 docker run --name mariadb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=输入数据库root用户的密码 -v /data/mariadb/data:/var/lib/mysql -d mariadb

      --name启动容器设置容器名称为mariadb

      -p设置容器的3306端口映射到主机3306端口

      -e MYSQL_ROOT_PASSWORD设置环境变量数据库root用户密码为输入数据库root用户的密码

      -v设置容器目录/var/lib/mysql映射到本地目录/data/mariadb/data

      -d后台运行容器mariadb并返回容器id

    6 docker ps -a 查看容器是否运行

    7 docker container update --restart=always 容器id   修改容器为自启动

    8 进入容器docker exec -it 容器Id bash

    9 在容器内登录数据库 mysql -uroot -proot密码

    10 修改远程登录j及密码

    1、设置远程登录:
    
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    2、修改用户密码,以root为例
    
    知道root密码,需要修改
    方法a. 登入数据库来修改
    # mysql -uroot -p /*输入密码进入*/  
    /*第一个方式:直接编辑数据库字段*/  
    MariaDB [(none)]> use mysql;  
    MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root';  
    MariaDB [mysql]> flush privileges;  
    MariaDB [mysql]> exit  
    /*第二个方式:修改密码,不用进入mysql*/  
    MariaDB [(none)]> SET password for 'root'@'localhost'=password('newpassword');  
    MariaDB [(none)]> exit;  
    
    忘记密码:
    # systemctl stop mariadb /*先停掉当前的mysql进程,不然执行下一步说进程已经存在*/  
    # mysqld_safe --skip-grant-tables & /*后台直接这个mysql,界面中还会出现日志,直接ctrl+c进入命令行输入*/   
    # ps -ef | grep mariadb /*看进程,会突出显示--skip-grant-tables*/  
      mysql     3607  3368  0 18:05 pts/0    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql   
      --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log   
      --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock  
    # mysql /*直接进入mysql,不需要密码等,执行第一步中方法a里两种方式中任何一种即可*/  
    MariaDB [(none)]> use mysql;  
    MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root';  
    MariaDB [mysql]> flush privileges;   
    MariaDB [mysql]> exit; /*这个时候用参数--skip-grant-tables启动的mysql已经会要求输入密码才能进入了*/  
    # pkill mysql /*用pkill来杀,kill不死,kill之后自动起来一个*/  
    # systemctl start mariadb /*启动正常的mysql*/


    MariaDB [(none)]> select host,user,authentication_string from user;
    ERROR 1046 (3D000): No database selected
    MariaDB [(none)]> 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
    MariaDB [mysql]> select host,user,authentication_string from user;
    +-----------+-------------+-------------------------------------------+
    | Host      | User        | authentication_string                     |
    +-----------+-------------+-------------------------------------------+
    | localhost | mariadb.sys |                                           |
    | localhost | root        | *02414E122D89A54B387E212E9BE95AA96D9DA3B9 |
    | %         | root        | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
    +-----------+-------------+-------------------------------------------+
    3 rows in set (0.001 sec)
    
    MariaDB [mysql]> ALTER USER 'root'@'%' IDENTIFIED BY 'xueqing@2020';
    Query OK, 0 rows affected (0.002 sec)
    
    MariaDB [mysql]> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.001 sec)
    
    MariaDB [mysql]> select host,user,authentication_string from user;
    +-----------+-------------+-------------------------------------------+
    | Host      | User        | authentication_string                     |
    +-----------+-------------+-------------------------------------------+
    | localhost | mariadb.sys |                                           |
    | localhost | root        | *02414E122D89A54B387E212E9BE95AA96D9DA3B9 |
    | %         | root        | *02414E122D89A54B387E212E9BE95AA96D9DA3B9 |
    +-----------+-------------+-------------------------------------------+
    3 rows in set (0.001 sec)
  • 相关阅读:
    mysql查询太慢,我们如何进行性能优化?
    详解MySQL事务原理
    精通MySQL之锁篇
    精通MySQL之索引篇,这篇注重练习!
    mysql数据结构及mvcc
    mysql-主从同步
    redis分布式锁
    售后系统构建和商品状态重构经验与总结
    【更新2021-4-25】如何处理PoshSSH 连接主机时的"New-SSHSession : Key exchange negotiation failed."故障
    计算几何---大牛们
  • 原文地址:https://www.cnblogs.com/zxqblogrecord/p/13425791.html
Copyright © 2020-2023  润新知