• Ubuntu18.04安装MySQL


    安装MySQL

    • Ubuntu:V18.04

    参考:https://www.jianshu.com/p/4583aebf247a

    sudo apt update
    sudo apt install mysql-server
    

    忘记mysql root密码

    参考:https://blog.csdn.net/luckytanggu/article/details/80251833

    1、停止mysql服务

    $ service mysql stop
    

    2、修改文件

    • 修改my.cnf文件
    # 查找my.cnf文件在哪里
    $ find / -name my.cnf
    /var/lib/dpkg/alternatives/my.cnf
    /etc/alternatives/my.cnf
    /etc/mysql/my.cnf
    
    # 修改my.cnf文件,在文件新增 skip-grant-tables,在启动mysql时不启动grant-tables,授权表
    $ sudo vim /etc/mysql/my.cnf
    [mysqld]
    skip-grant-tables
    
    • 修改mysqld.cnf文件
    # 注意:不同 mysql 版本此配置文件位置和名字可能不同
    sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf # mysql 5.7.23
    # 找到将bind-address = 127.0.0.1注销​
    #bind-address            = 127.0.0.1
    

    3、启动mysql服务

    $ sudo /etc/init.d/mysql restart
    

    4、更改mysql root用户密码

    $ mysql
    
    # 选择mysql数据库
    mysql> use mysql;
    
    # 更改user表中root用户密码
    mysql> update mysql.user set authentication_string=PASSWORD("123456") where user='root';
    # root用户使用mysql_native_password插件
    mysql> UPDATE msyql.user SET plugin='mysql_native_password' WHERE User='root';  
    # 允许远程登录
    mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
    mysql> flush privileges;
    
    # 注意:可能不同的数据库版本密码的字段名称不一样
    # 我的数据库版本是5.7.21,user表中的密码字段是:authentication_string
    mysql> select version();
    +-------------------------+
    | version()               |
    +-------------------------+
    | 5.7.21-0ubuntu0.16.04.1 |
    +-------------------------+
    1 row in set (0.00 sec)
    
    # 可以通过以下命令查看user表的密码字段名称
    mysql> show create table userG;
    

    5、再次修改my.cnf文件

    $ sudo vim /etc/mysql/my.cnf
    [mysqld]
    # skip-grant-tables
    

    6、再次重启mysql

    $ sudo /etc/init.d/mysql restart
    
    # 现在我们可以用新root密码登录mysql了
    $ mysql -u root -p
    
  • 相关阅读:
    667. Beautiful Arrangement II
    695. Max Area of Island
    485. Max Consecutive Ones
    coedforces #481Div(3)(ABCDEFG)
    躲藏
    车辆问题(贪心)
    最小化代价(优先队列)
    PUBG
    hdu 2647 Reward(拓扑排序+优先队列)
    HDU 3342 Legal or Not(判断环)
  • 原文地址:https://www.cnblogs.com/1fengchen1/p/14082307.html
Copyright © 2020-2023  润新知