ubuntu18安装mysql,并配置编码和访问权限

  • 安装mysql
sudo apt install mysql-server
  • 启动mysql服务
sudo service mysql start
sudo ps -ef | grep mysql
sudo netstat -tlnp | grep 3306
  • mysql修改编码以支持中文
sudo vim /etc/mysql/my.cnf:
  • 复制以下内容到my.cnf
[client]
default-character-set = utf8

[mysqld]
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_ci
  • 允许所有ip访问mysql服务

    sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
    
    • 找到bind-address配置项,修改为以下内容
      • bind-address = 0.0.0.0
  • 允许所有ip访问mysql都有权限

    • 登录mysql
    mysql -u root -p123456
    
    • GRANT ALL PRIVILEGES授予所有权限,*.*所有表,root用户,%所有的ip访问,IDENTIFIED BY ‘123456‘密码是123456
    GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION;
    
    • 刷新权限
    flush privileges;
    
    • 退出mysql
    exit;
    
  • 重启mysql服务

    sudo service mysql restart
    
  • 登录后查看编码信息

    show variables like ‘%char%‘;
    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | utf8                       |
    | character_set_connection | utf8                       |
    | character_set_database   | utf8                       |
    | character_set_filesystem | binary                     |
    | character_set_results    | utf8                       |
    | character_set_server     | utf8                       |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.02 sec)
    
  • 停止mysql服务

    sudo service mysql stop
    

ubuntu18安装mysql,并配置编码和访问权限

上一篇:mysql用户管理


下一篇:MySQL数据库部分命令