• Ubuntu 16.04安装Mysql


    第一步:

    ubuntu@VM-0-12-ubuntu:~$ 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:
    Package configuration
    
    
    
    
    
    
    
    
    
    
                                                       ┌──────┤ Configuring mysql-server-5.7 ├───────┐
                                                       │                                             │
                                                       │                                             │
                                                       │ Repeat password for the MySQL "root" user:  │
                                                       │                                             │
                                                       │ ****_______________________________________ │
                                                       │                                             │
                                                       │                   <Ok>                      │
                                                       │                                             │
                                                       └─────────────────────────────────────────────┘
    
    
    
    
    
    
    
    
    
    
    
    Selecting previously unselected package mysql-common.                                                                                               
    (Reading database ... 66461 files and directories currently installed.)
    Preparing to unpack .../mysql-common_5.7.27-0ubuntu0.16.04.1_all.deb ...
    Unpacking mysql-common (5.7.27-0ubuntu0.16.04.1) ...
    Selecting previously unselected package libaio1:amd64.
    Preparing to unpack .../libaio1_0.3.110-2_amd64.deb ...
    Unpacking libaio1:amd64 (0.3.110-2) ...
    Selecting previously unselected package mysql-client-core-5.7.
    Preparing to unpack .../mysql-client-core-5.7_5.7.27-0ubuntu0.16.04.1_amd64.deb ...
    Unpacking mysql-client-core-5.7 (5.7.27-0ubuntu0.16.04.1) ...
    Selecting previously unselected package mysql-client-5.7.
    Preparing to unpack .../mysql-client-5.7_5.7.27-0ubuntu0.16.04.1_amd64.deb ...
    Unpacking mysql-client-5.7 (5.7.27-0ubuntu0.16.04.1) ...
    Selecting previously unselected package mysql-server-core-5.7.
    Preparing to unpack .../mysql-server-core-5.7_5.7.27-0ubuntu0.16.04.1_amd64.deb ...
    Unpacking mysql-server-core-5.7 (5.7.27-0ubuntu0.16.04.1) ...
    Selecting previously unselected package libevent-core-2.0-5:amd64.
    Preparing to unpack .../libevent-core-2.0-5_2.0.21-stable-2ubuntu0.16.04.1_amd64.deb ...
    Unpacking libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
    Processing triggers for libc-bin (2.23-0ubuntu9) ...
    Processing triggers for man-db (2.7.5-1) ...
    Setting up mysql-common (5.7.27-0ubuntu0.16.04.1) ...
    update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
    Selecting previously unselected package mysql-server-5.7.
    (Reading database ... 66629 files and directories currently installed.)
    Preparing to unpack .../mysql-server-5.7_5.7.27-0ubuntu0.16.04.1_amd64.deb ...
    Unpacking mysql-server-5.7 (5.7.27-0ubuntu0.16.04.1) ...
    Selecting previously unselected package libhtml-tagset-perl.
    Preparing to unpack .../libhtml-tagset-perl_3.20-2_all.deb ...
    Unpacking libhtml-tagset-perl (3.20-2) ...
    Selecting previously unselected package liburi-perl.
    Preparing to unpack .../liburi-perl_1.71-1_all.deb ...
    Unpacking liburi-perl (1.71-1) ...
    Selecting previously unselected package libhtml-parser-perl.
    Preparing to unpack .../libhtml-parser-perl_3.72-1_amd64.deb ...
    Unpacking libhtml-parser-perl (3.72-1) ...
    Selecting previously unselected package libcgi-pm-perl.
    Preparing to unpack .../libcgi-pm-perl_4.26-1_all.deb ...
    Unpacking libcgi-pm-perl (4.26-1) ...
    Selecting previously unselected package libfcgi-perl.
    Preparing to unpack .../libfcgi-perl_0.77-1build1_amd64.deb ...
    Unpacking libfcgi-perl (0.77-1build1) ...
    Selecting previously unselected package libcgi-fast-perl.
    Preparing to unpack .../libcgi-fast-perl_1%3a2.10-1_all.deb ...
    Unpacking libcgi-fast-perl (1:2.10-1) ...
    Selecting previously unselected package libencode-locale-perl.
    Preparing to unpack .../libencode-locale-perl_1.05-1_all.deb ...
    Unpacking libencode-locale-perl (1.05-1) ...
    Selecting previously unselected package libhtml-template-perl.
    Preparing to unpack .../libhtml-template-perl_2.95-2_all.deb ...
    Unpacking libhtml-template-perl (2.95-2) ...
    Selecting previously unselected package libtimedate-perl.
    Preparing to unpack .../libtimedate-perl_2.3000-2_all.deb ...
    Unpacking libtimedate-perl (2.3000-2) ...
    Selecting previously unselected package libhttp-date-perl.
    Preparing to unpack .../libhttp-date-perl_6.02-1_all.deb ...
    Unpacking libhttp-date-perl (6.02-1) ...
    Selecting previously unselected package libio-html-perl.
    Preparing to unpack .../libio-html-perl_1.001-1_all.deb ...
    Unpacking libio-html-perl (1.001-1) ...
    Selecting previously unselected package liblwp-mediatypes-perl.
    Preparing to unpack .../liblwp-mediatypes-perl_6.02-1_all.deb ...
    Unpacking liblwp-mediatypes-perl (6.02-1) ...
    Selecting previously unselected package libhttp-message-perl.
    Preparing to unpack .../libhttp-message-perl_6.11-1_all.deb ...
    Unpacking libhttp-message-perl (6.11-1) ...
    Selecting previously unselected package mysql-server.
    Preparing to unpack .../mysql-server_5.7.27-0ubuntu0.16.04.1_all.deb ...
    Unpacking mysql-server (5.7.27-0ubuntu0.16.04.1) ...
    Processing triggers for systemd (229-4ubuntu21.2) ...
    Processing triggers for ureadahead (0.100.0-19) ...
    Processing triggers for man-db (2.7.5-1) ...
    Setting up libaio1:amd64 (0.3.110-2) ...
    Setting up mysql-client-core-5.7 (5.7.27-0ubuntu0.16.04.1) ...
    Setting up mysql-client-5.7 (5.7.27-0ubuntu0.16.04.1) ...
    Setting up mysql-server-core-5.7 (5.7.27-0ubuntu0.16.04.1) ...
    Setting up libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
    Setting up mysql-server-5.7 (5.7.27-0ubuntu0.16.04.1) ...
    update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
    Renaming removed key_buffer and myisam-recover options (if present)
    Setting up libhtml-tagset-perl (3.20-2) ...
    Setting up liburi-perl (1.71-1) ...
    Setting up libhtml-parser-perl (3.72-1) ...
    Setting up libcgi-pm-perl (4.26-1) ...
    Setting up libfcgi-perl (0.77-1build1) ...
    Setting up libcgi-fast-perl (1:2.10-1) ...
    Setting up libencode-locale-perl (1.05-1) ...
    Setting up libhtml-template-perl (2.95-2) ...
    Setting up libtimedate-perl (2.3000-2) ...
    Setting up libhttp-date-perl (6.02-1) ...
    Setting up libio-html-perl (1.001-1) ...
    Setting up liblwp-mediatypes-perl (6.02-1) ...
    Setting up libhttp-message-perl (6.11-1) ...
    Setting up mysql-server (5.7.27-0ubuntu0.16.04.1) ...
    Processing triggers for libc-bin (2.23-0ubuntu9) ...
    Processing triggers for systemd (229-4ubuntu21.2) ...
    Processing triggers for ureadahead (0.100.0-19) ...
    ubuntu@VM-0-12-ubuntu:~$

    2、检查是否安装成功

    ubuntu@VM-0-12-ubuntu:~$ sudo netstat -tap | grep mysql
    tcp 0 0 localhost.localdo:mysql *:* LISTEN 7086/mysqld
    ubuntu@VM-0-12-ubuntu:~$

    3、进入数据

    ubuntu@VM-0-12-ubuntu:~$ mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 4
    Server version: 5.7.27-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>

    4、查看数据库版本

    mysql> status;
    --------------
    mysql  Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using  EditLine wrapper

    5、设置mysql运行远程访问:编辑文件 /etc/mysql/mysql.conf.d/mysqld.cnf

    ubuntu@VM-0-12-ubuntu:/etc/mysql/mysql.conf.d$ sudo vi mysqld.cnf
    #
    # The MySQL database server configuration file.
    #
    # You can copy this to one of:
    # - "/etc/mysql/my.cnf" to set global options,
    # - "~/.my.cnf" to set user-specific options.
    # 
    # One can use all long options that the program supports.
    # Run program with --help to get a list of available options and with
    # --print-defaults to see which it would actually understand and use.
    #
    # For explanations see
    # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
    
    # This will be passed to all mysql clients
    # It has been reported that passwords should be enclosed with ticks/quotes
    # escpecially if they contain "#" chars...
    # Remember to edit /etc/mysql/debian.cnf when changing the socket location.
    
    # Here is entries for some specific programs
    # The following values assume you have at least 32M ram
    
    [mysqld_safe]
    socket          = /var/run/mysqld/mysqld.sock
    nice            = 0
    
    [mysqld]
    #
    # * Basic Settings
    #
    user            = mysql
    pid-file        = /var/run/mysqld/mysqld.pid
    socket          = /var/run/mysqld/mysqld.sock
    port            = 3306
    basedir         = /usr
    datadir         = /var/lib/mysql
    tmpdir          = /tmp
    lc-messages-dir = /usr/share/mysql
    skip-external-locking
    #
    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    bind-address            = 127.0.0.1
    #
    # * Fine Tuning
    #
    key_buffer_size         = 16M
    max_allowed_packet      = 16M
    thread_stack            = 192K
    thread_cache_size       = 8
    # This replaces the startup script and checks MyISAM tables if needed
    # the first time they are touched
    myisam-recover-options  = BACKUP
    #max_connections        = 100
    #table_cache            = 64
    tmpdir          = /tmp
    lc-messages-dir = /usr/share/mysql
    skip-external-locking
    #
    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    #bind-address           = 127.0.0.1
    #
    # * Fine Tuning
    #
    key_buffer_size         = 16M
    max_allowed_packet      = 16M
    thread_stack            = 192K
    thread_cache_size       = 8
    # This replaces the startup script and checks MyISAM tables if needed
    # the first time they are touched
    myisam-recover-options  = BACKUP
    #max_connections        = 100
    #table_cache            = 64
    #thread_concurrency     = 10
    #
    # * Query Cache Configuration
    #
    query_cache_limit       = 1M
    query_cache_size        = 16M
    #
    # * Logging and Replication
    #
    # Both location gets rotated by the cronjob.
    # Be aware that this log type is a performance killer.
    # As of 5.1 you can enable the log at runtime!
    #general_log_file        = /var/log/mysql/mysql.log
    "mysqld.cnf" 104L, 3029C written
    ubuntu@VM-0-12-ubuntu:/etc/mysql/mysql.conf.d$ mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 5
    Server version: 5.7.27-0ubuntu0.16.04.1 (Ubuntu)
    
    #
    # The MySQL database server configuration file.
    #
    # You can copy this to one of:
    # - "/etc/mysql/my.cnf" to set global options,
    # - "~/.my.cnf" to set user-specific options.
    # 
    # One can use all long options that the program supports.
    # Run program with --help to get a list of available options and with
    # --print-defaults to see which it would actually understand and use.
    #
    # For explanations see
    # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
    
    # This will be passed to all mysql clients
    # It has been reported that passwords should be enclosed with ticks/quotes
    # escpecially if they contain "#" chars...
    # Remember to edit /etc/mysql/debian.cnf when changing the socket location.
    
    # Here is entries for some specific programs
    # The following values assume you have at least 32M ram
    
    [mysqld_safe]
    socket          = /var/run/mysqld/mysqld.sock
    nice            = 0
    
    [mysqld]
    #
    # * Basic Settings
    #
    user            = mysql
    pid-file        = /var/run/mysqld/mysqld.pid
    socket          = /var/run/mysqld/mysqld.sock
    port            = 3306
    basedir         = /usr
    datadir         = /var/lib/mysql
    tmpdir          = /tmp
    lc-messages-dir = /usr/share/mysql
    skip-external-locking
    #
    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    bind-address           = 127.0.0.1
    #
    # * Fine Tuning
    #
    key_buffer_size         = 16M
    max_allowed_packet      = 16M
    thread_stack            = 192K
    thread_cache_size       = 8
    # This replaces the startup script and checks MyISAM tables if needed
    # the first time they are touched
    myisam-recover-options  = BACKUP
    #max_connections        = 100
    #table_cache            = 64
    #thread_concurrency     = 10
    #
    # * Query Cache Configuration
    #
    query_cache_limit       = 1M
    query_cache_size        = 16M
    #
    # * Logging and Replication
    #
    # Both location gets rotated by the cronjob.
    # Be aware that this log type is a performance killer.
    # As of 5.1 you can enable the log at runtime!
    #general_log_file        = /var/log/mysql/mysql.log
    #general_log             = 1
    #
    # Error log - should be very few entries.
    #
    log_error = /var/log/mysql/error.log
    #
    # Here you can see queries with especially long duration
    #log_slow_queries       = /var/log/mysql/mysql-slow.log
    #long_query_time = 2
    #log-queries-not-using-indexes
    #
    # The following can be used as easy to replay backup logs or for replication.
    # note: if you are setting up a replication slave, see README.Debian about
    #       other settings you may need to change.
    #server-id              = 1
    #log_bin                        = /var/log/mysql/mysql-bin.log
    expire_logs_days        = 10
    max_binlog_size   = 100M
    #binlog_do_db           = include_database_name
    #binlog_ignore_db       = include_database_name
    #
    # * InnoDB
    #
    # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
    # Read the manual for more InnoDB related options. There are many!
    #
    # * Security Features
    #
    # Read the manual, too, if you want chroot!
    # chroot = /var/lib/mysql/
    #
    # For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
    #
    # ssl-ca=/etc/mysql/cacert.pem
    # ssl-cert=/etc/mysql/server-cert.pem
    # ssl-key=/etc/mysql/server-key.pem
    -- INSERT --                                                                                                                       104,1         Bot

    键盘按I,进入编辑模式找到

    bind-address           = 127.0.0.1

    将其注释,结果如下

    #bind-address           = 127.0.0.1

    键盘按Esc,然后输入冒号:(Shift+对应键盘键),输入wq在回车,即保存并退出

    6、进mysql执行授权命令:

    mysql> grant all on *.* to root@'%' identified by '你的数据库密码' with grant option;
    mysql> flush privileges;

    执行以上两句命令之后就可以退出mysql并重启mysql了

    7、重启mysql

    ubuntu@VM-0-12-ubuntu:sudo service mysql restart

    执行以上七个步骤,数据库即可被远程连接了

  • 相关阅读:
    02_类和对象
    Django_数据库增删改查——增
    Django_同步数据库
    Django_models类属性。
    CSS_垂直居中
    CSS_背景属性
    CSS_定位
    CSS_浮动
    CSS_盒子模型
    CSS_元素的分类
  • 原文地址:https://www.cnblogs.com/dfsu/p/11511454.html
Copyright © 2020-2023  润新知