美文网首页
[MySQL专题-01] Ubuntu平台安装MySQL 5.7

[MySQL专题-01] Ubuntu平台安装MySQL 5.7

作者: ccczyl2006 | 来源:发表于2019-11-19 21:32 被阅读0次

    Ubuntu平台安装

    • MySQL的软件包在Ubuntu默认软件仓库中可用,默认的版本号为5.7.27,可通过以下命令安装:

      yjf@vbox:~$ sudo apt update
      yjf@vbox:~$ sudo apt install mysql-server
      
    • 运行mysql_secure_installation命令进行MySQL以下六步配置。

      yjf@vbox-ubuntu:~$ 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      #1 配置是否需要密码插件 选择n
      
      Please set the password for root here.
      New password: 
      Re-enter new password:                          #2 为root用户配置密码
      
      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) : y    
      #3 移除匿名用户
      Success.
      
      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    #4 配置root不允许远程访问
      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) : y #5 移除测试数据库
      Dropping test database... Success.
      - Removing privileges on test database... Success.
      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 #6 重新加载权限表 Success. 
      All done!
      
    - 运行`sudo service mysql status`检查`MySQL`服务是否启动成功。
    
    - 配置远程访问用户
    
      ```bash
      yjf@vbox:~$ sudo mysql -uroot -p      #需本机登录且输入上面配置的密码
      Enter password:
      
      mysql> CREATE USER yjf IDENTIFIED BY 'yjf';   #新建用户yjf 密码为yjf
      mysql> GRANT ALL PRIVILEGES ON *.* TO 'yjf'@'%' IDENTIFIED BY 'yjf' WITH GRANT OPTION; #f授权用户yjf
      mysql> FLUSH PRIVILEGES;
    
    • 解决远程访问问题和乱码问题。

      #1 修改/etc/mysql/mysql.conf.d/mysqld.cnf文件, 如下
      # bind-address = 127.0.0.1 增加注释
      # 在[mysqld]下增加以下两行配置
      character_set_server=utf8
      init_connect='SET NAMES utf8'
      
    • 重启mysql服务,常用的命令如下:

      # sudo service mysql restart  //重启
      # sudo service mysql start    //启动mysql服务
      # sudo service mysql status   //查看MySQL的启动状态,下图显示正常启动.
      # sudo service mysql stop     //停止mysql服务
      
      #常用的mysql默认配置文件位置
      # 配置文件:/etc/my.cnf
      # 日志文件:/var/log//var/log/mysqld.log
      # 服务启动脚本:/usr/lib/systemd/system/mysqld.service
      # socket文件:/var/run/mysqld/mysqld.pid
      

    相关文章

      网友评论

          本文标题:[MySQL专题-01] Ubuntu平台安装MySQL 5.7

          本文链接:https://www.haomeiwen.com/subject/tangictx.html