1. 程式人生 > 其它 >java入門(一)

java入門(一)

安裝mysql5.7

  1. 在aliyun機器上安裝和配置mysql

  2. 在安裝MySQL服務的時候

    [root@localhost ~]# yum -y install mysql-community-server
    
  3. 遇到以下報錯

    Downloading packages:
    warning: /var/cache/yum/x86_64/2.1903/mysql57-community/packages/mysql-community-common-5.7.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
    Public key for mysql-community-common-5.7.37-1.el7.x86_64.rpm is not installed
    (1/4): mysql-community-common-5.7.37-1.el7.x86_64.rpm                                                  | 311 kB  00:00:01
    (2/4): mysql-community-libs-5.7.37-1.el7.x86_64.rpm                                                    | 2.4 MB  00:00:01
    (3/4): mysql-community-client-5.7.37-1.el7.x86_64.rpm                                                  |  25 MB  00:00:08
    (4/4): mysql-community-server-5.7.37-1.el7.x86_64.rpm                                                  | 174 MB  00:00:42
    ------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                         4.4 MB/s | 202 MB  00:00:45
    Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    Importing GPG key 0x5072E1F5:
     Userid     : "MySQL Release Engineering <[email protected]>"
     Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
     Package    : mysql57-community-release-el7-10.noarch (@/mysql57-community-release-el7-10.noarch)
     From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
    Public key for mysql-community-server-5.7.37-1.el7.x86_64.rpm is not installed
    
     Failing package is: mysql-community-server-5.7.37-1.el7.x86_64
     GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    
  4. 需要需要以下yum檔案,指定某個版本

    vi /etc/yum.repos.d/mysql-community.repo
    
    # Enable to use MySQL 5.6
    [mysql56-community]
    name=MySQL 5.6 Community Server
    
    baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
    enabled=1
    gpgcheck=1
    # gpgcheck=0表示預設此版本
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    

啟動MySQL

  1. 啟動MySQL服務systemctl start mysqld.service

  2. 重啟systemctl restart mysqld.service

  3. 停止systemctl stop mysqld.service

  4. 檢視狀態systemctl status mysqld.service

  5. 配置MySQL的開機啟動systemctl enable mysqld

  6. 重新整理配置生效systemctl daemon-reload


登陸MySQL

  1. 第一次登陸,先檢視內建密碼

    grep "password" /var/log/mysqld.log
    
  2. root登陸mysql -u root -p

    • 需要進行修改密碼
    SET PASSWORD = PASSWORD('密碼');
    
    mysql> set global validate_password_policy=0;  //改變密碼等級
    mysql> set global validate_password_length=4;   //改變密碼最小長度
    
  3. 配置遠端登陸

    MySQL預設root使用者只能本地登入,如果要遠端連線,要簡單設定下,這裡直接用root來遠端登入不新增其他角色。

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION;
    
    1. *.*的意思是所有庫的所有表
    2. To後面跟的是使用者名稱
    3. @後面跟的是ip地址
    4. %代表所有ip地址
    5. identified by後面的是密碼
    flush privileges;
    

    需要注意mysql的配置檔案中的bindaddress 的引數和skip-networking配置

    bindaddress : 設定哪些ip地址被配置,使得mysql伺服器只回應哪些ip地址的請求),最好註釋掉該引數或設定成為127.0.0.1以外的值

    skip-networking : 如果設定了該引數項,將導致所有TCP/IP埠沒有被監聽,也就是說出了本機,其他客戶端都無法用網路連線到本mysql伺服器,所以應該註釋掉該引數


新增埠

  1. 新增3306

    firewall-cmd --zone=public --add-port=3306/tcp --permanent;
    
  2. 檢視防火牆狀態systemctl status firewalld

  3. 開啟防火牆systemctl start firewalld

  4. 重新啟用3306

    firewall-cmd --zone=public --add-port=3306/tcp --permanent;
    
  5. 重啟防火牆firewall-cmd --reload


收尾動作

  1. 檢視MySQL的配置檔案cat /etc/my.cnf

    [root@blue-ocean tmp]# cat /etc/my.cnf
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    
  2. vim /etc/my.cnf

    [mysqld] 
    
    character_set_server=utf8
    init_connect='SET NAMES utf8'
    
  3. 預設配置檔案路徑

    /etc/my.cnf #這是mysql的主配置檔案
    /var/lib/mysql #mysql資料庫的資料庫檔案存放位置
    /var/log mysql #資料庫的日誌輸出存放位置