美文网首页
ubuntu16安装mysql

ubuntu16安装mysql

作者: 天草二十六_简村人 | 来源:发表于2019-07-10 10:11 被阅读0次

    一、执行三条命令
    1、sudo apt-get install mysql-server
    我本机报错如下,安装失败!

    root@ubuntu:/opt# sudo apt-get install mysql-server
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following additional packages will be installed:
      libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5
      libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
      libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
      libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common
      mysql-server-5.7 mysql-server-core-5.7
    Suggested packages:
      libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca
    The following NEW packages will be installed:
      libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.0-5
      libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
      libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
      libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common
      mysql-server mysql-server-5.7 mysql-server-core-5.7
    0 upgraded, 21 newly installed, 0 to remove and 186 not upgraded.
    Need to get 19.3 MB of archives.
    After this operation, 162 MB of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Abort.
    

    需要更新系统!!!

     sudo apt-get update
    
    
    apt-get install mysql-server.png

    设置root用户的密码和确认密码。

    2、sudo apt-get install mysql-client

    root@ubuntu:/opt# sudo apt-get install mysql-client
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      mysql-client
    0 upgraded, 1 newly installed, 0 to remove and 186 not upgraded.
    Need to get 10.0 kB of archives.
    After this operation, 110 kB of additional disk space will be used.
    Get:1 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-client all 5.7.26-0ubuntu0.16.04.1 [10.0 kB]
    Fetched 10.0 kB in 1s (6211 B/s)       
    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US:en",
        LC_ALL = (unset),
        LANG = "zh_CN.UTF-8"
        are supported and installed on your system.
    perl: warning: Falling back to the standard locale ("C").
    locale: Cannot set LC_CTYPE to default locale: No such file or directory
    locale: Cannot set LC_MESSAGES to default locale: No such file or directory
    locale: Cannot set LC_ALL to default locale: No such file or directory
    Selecting previously unselected package mysql-client.
    (Reading database ... 66984 files and directories currently installed.)
    Preparing to unpack .../mysql-client_5.7.26-0ubuntu0.16.04.1_all.deb ...
    Unpacking mysql-client (5.7.26-0ubuntu0.16.04.1) ...
    Setting up mysql-client (5.7.26-0ubuntu0.16.04.1) ...
    

    3、 sudo apt-get install libmysqlclient-dev
    安装失败:

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following additional packages will be installed:
      libc-dev-bin libc6 libc6-dev libmysqlclient20 linux-libc-dev manpages-dev zlib1g-dev
    Suggested packages:
      glibc-doc
    The following NEW packages will be installed:
      libc-dev-bin libc6-dev libmysqlclient-dev libmysqlclient20 linux-libc-dev manpages-dev zlib1g-dev
    The following packages will be upgraded:
      libc6
    1 upgraded, 7 newly installed, 0 to remove and 185 not upgraded.
    Need to get 9766 kB of archives.
    After this operation, 34.1 MB of additional disk space will be used.
    Do you want to continue? [Y/n] y
    Abort.
    

    解决方法:执行sudo apt install -y libmysqlclient-dev

    二、测试是否安装成功:
    sudo netstat -tap | grep mysql


    netstat -tap | grep mysql.png

    三、设置远程访问权限

    root@ubuntu:/opt# mysql -uroot -p
    Enter password: (输入root用户的密码,最上面第一步输入的密码)
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.7.26-0ubuntu0.16.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> flush privileges;    
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exit;
    Bye
    

    如果你是直接这样设置,使用客户端连接该数据库,会报错--拒绝连接。
    Can't connect to MySQL server xxx.xxx.xxx.xxx (10061)

    解决方法:
    sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
    注释掉bind-address = 127.0.0.1:

    注释掉bind-address.png

    重启mysql:

    service mysql restart

    四、配置mysql默认字符集
    在 /ect/mysql/my.cnf 中写入:

    [client]
    default-character-set = utf8
    [mysqld]
    character-set-server = utf8
    [mysql]
    default-character-set = utf8

    配置mysql默认字符集.png

    相关文章

      网友评论

          本文标题:ubuntu16安装mysql

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