分类: MySQL

  • Linux/Ubuntu 安装 docker mysql 5.7

    # 安装 docker
    apt install docker.io
    
    # 拉取 mysql 镜像
    docker pull mysql:5.7.39
    
    # 实例化一个数据库容器
    docker run --name mysql5.7 -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7.39

    password 为用户 root 的密码

    查看运行中的容器,第一列为容器id

    docker ps

    查看容器 IP ,<container_id> 修改为上面命令输出的容器id

    docker inspect <container_id> | grep -i ipaddress

    连接 MySQL,172.17.0.2 为容器 IP

    mysql -h172.17.0.2 -uroot -p

    输入密码即连接成功。

  • MySQL 8.0 general log 设置

    操作系统版本:Ubuntu 20.10
    MySQL版本:mysql Ver 8.0.21-0ubuntu0.20.04.4
    开启 MySQL general log 步骤:
    查找 mysqld 都读取了哪些配置文件:
    /usr/sbin/mysqld –verbose –help | grep -A 1 “Default options”
    列出了3个文件
    /etc/my.cnf
    /etc/mysql/my.cnf
    ~/.my.cnf
    这些文件只有 /etc/mysql/my.cnf 有如下内容
    !includedir /etc/mysql/conf.d/
    !includedir /etc/mysql/mysql.conf.d/
    最终在文件 /etc/mysql/mysql.conf.d/mysqld.cnf 中找到
    general_log_file 和 general_log 的配置
    设定赋值:
    general_log = 1
    general_log_file = /tmp/mysql.log
    general_log_file 对应的文件 /tmp/mysql.log 必须存在
    并且此文件的所属用户是:配置文件里面的[mysqld]中user的值,默认是mysql。
    如果属主不一致,即使其他用户有权限写这个日志文件,
    general_log 还是无法开启,开启时会报 permission denied 错误。
    修改属主
    chown mysql:mysql /tmp/mysql.log
    然后保存配置文件并退出,重新启动 mysql
    systemctl restart mysql.service
    最后使用 tail -f /tmp/mysql.log 就可以实时监控log了。
    生产环境开启这个日志要谨慎!
     
    参考资料
  • phpMyAdmin连接远程服务器配置

    phpMyAdmin登陆界面默认的MySQL服务器只有localhost

    如果想连接其他服务器上的MySQL

    此时只需要在config.inc.php中增加配置就可以了

    首先复制文件 config.sample.inc.php 为 config.inc.php

    然后找到下面的代码片段

     

    /**
     * First server
     */
    $i++;
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = 'localhost';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;

    复制为

    /**
     * Second server
     */
    $i++;
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = '192.168.1.11';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['AllowNoPassword'] = false;

     

    注意第8行,新增加的数据库服务器地址为 192.168.1.11

    这样在登录界面就可以看到新增加的服务器了。

    操作视频

    https://www.bilibili.com/video/BV1Ji4y177xc/

  • Ubuntu 18.04.1 LTS 安装mysql

    Ubuntu 18.04.1 LTS 安装mysql命令

    apt install mysql-server

    安装完毕后,在命令行输入mysql,即可登陆数据库控制台

    默认使用数据库的root账号登陆了

    如果期望设定root账号的密码,可以先执行查询

    select Host,User,authentication_string from mysql.user limit 10;

    可以看到root用户未设定密码

    按顺序执行下列命令

    update mysql.user set authentication_string=password(‘88884444′) where user=’root’ and Host =’localhost’;

    update user set plugin=”mysql_native_password”;
    flush privileges;

    即可将密码修改为88884444

    下次登陆数据库时,使用命令

    mysql -hlocalhost -uroot -p

    然后数据密码88884444即可登陆