zoukankan      html  css  js  c++  java
  • ubuntu18.04TLS 安装mysql

    ubuntu18.04TLS 安装mysql

    • 准备环境

      ubuntu 18.04 TLS

      mysql 5.7.35

    • 卸载之前安装的mysql服务

      # 删除数据文件
      sudo rm /var/lib/mysql/ -R
      # 删除配置文件
      sudo rm /etc/mysql/ -R
      # 卸载mysql服务端和客户端
      sudo apt-get autoremove mysql* --purge
      sudo apt-get remove apparmor
      # 检查是否卸载干净,sudo apt-get remove xxx
      dpkg --list|grep mysql
      
    • 安装

      • 安装mysql服务

        sudo apt-get install mysql-server
        
      • 初始化服务配置

        sudo mysql_secure_installation
        
        # 选项
        Securing the MySQL server deployment.
        
        Connecting to MySQL using a blank password.
        
        VALIDATE PASSWORD PLUGIN can be used to test passwords
        and improve security. It checks the strength of password
        and allows the users to set only those passwords which are
        secure enough. Would you like to setup VALIDATE PASSWORD plugin?
        
        Press y|Y for Yes, any other key for No: n # 我的选项
        Please set the password for root here.
        
        New password: xxx
        
        Re-enter new password: xxx
        
        By default, a MySQL installation has an anonymous user,
        allowing anyone to log into MySQL without having to have
        a user account created for them. This is intended only for
        testing, and to make the installation go a bit smoother.
        You should remove them before moving into a production
        environment.
        
        Remove anonymous users? (Press y|Y for Yes, any other key for No) : n # 我的选项
        
         ... skipping.
        
        
        Normally, root should only be allowed to connect from
        'localhost'. This ensures that someone cannot guess at
        the root password from the network.
        
        Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y # 我的选项
        Success.
        
        By default, MySQL comes with a database named 'test' that
        anyone can access. This is also intended only for testing,
        and should be removed before moving into a production
        environment.
        
        
        Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n # 我的选项
        
         ... skipping.
        Reloading the privilege tables will ensure that all changes
        made so far will take effect immediately.
        
        Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y # 我的选项
        Success.
        
        All done!
        
      • 这个版本会有设置密码不生效的情况

        # 查看这个配置文件
        sudo cat /etc/mysql/debian.cnf
        # 配置文件如下所示:
        root@instance:~# sudo cat /etc/mysql/debian.cnf
        # Automatically generated for Debian scripts. DO NOT TOUCH!
        [client]
        host     = localhost
        user     = debian-sys-maint
        password = nKmBg4nRX7LMxpKz
        socket   = /var/run/mysqld/mysqld.sock
        [mysql_upgrade]
        host     = localhost
        user     = debian-sys-maint
        password = nKmBg4nRX7LMxpKz
        socket   = /var/run/mysqld/mysqld.sock
        
        # 使用用户debian-sys-maint进行登录
        mysql -u debian-sys-maint -pnKmBg4nRX7LMxpKz
        
        # 使用mysql数据库
        use mysql;
        # 更新user表中的root的密码
        update user set authentication_string=password("你的密码") where user='root';
        # 更换客户端支持的加密方式,这里非常重要
        update user set plugin="mysql_native_password";
        # 重新加载权限表
        flush privileges;
        
      • 登录客户端

        mysql -u root -p您的密码
        
  • 相关阅读:
    [BZOJ3043]IncDec Sequence
    【NOIP2015】字串
    [NOIP]2016天天爱跑步
    【NOIP2015】运输计划
    [poj3565]Ants
    【ZOJ2760】How Many Shortest Path
    [POJ3281] Dining
    P1077摆花
    校内测之zay与银临 (day2)
    P1880石子合并
  • 原文地址:https://www.cnblogs.com/wuxiaoshi/p/15344119.html
Copyright © 2011-2022 走看看