java入門(一)
阿新 • • 發佈:2022-03-16
安裝mysql5.7
-
在安裝MySQL服務的時候
[root@localhost ~]# yum -y install mysql-community-server
-
遇到以下報錯
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
-
需要需要以下
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
-
啟動MySQL服務
systemctl start mysqld.service
-
重啟
systemctl restart mysqld.service
-
停止
systemctl stop mysqld.service
-
檢視狀態
systemctl status mysqld.service
-
配置MySQL的開機啟動
systemctl enable mysqld
-
重新整理配置生效
systemctl daemon-reload
登陸MySQL
-
第一次登陸,先檢視內建密碼
grep "password" /var/log/mysqld.log
-
用
root
登陸mysql -u root -p
- 需要進行修改密碼
SET PASSWORD = PASSWORD('密碼');
mysql> set global validate_password_policy=0; //改變密碼等級 mysql> set global validate_password_length=4; //改變密碼最小長度
-
配置遠端登陸
MySQL預設root使用者只能本地登入,如果要遠端連線,要簡單設定下,這裡直接用root來遠端登入不新增其他角色。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION;
-
*.*
的意思是所有庫的所有表 -
To
後面跟的是使用者名稱 -
@
後面跟的是ip
地址 -
%
代表所有ip
地址 -
identified by
後面的是密碼
flush privileges;
需要注意
mysql
的配置檔案中的bindaddress
的引數和skip-networking
配置bindaddress
: 設定哪些ip地址被配置,使得mysql
伺服器只回應哪些ip地址的請求),最好註釋掉該引數或設定成為127.0.0.1以外的值skip-networking
: 如果設定了該引數項,將導致所有TCP/IP
埠沒有被監聽,也就是說出了本機,其他客戶端都無法用網路連線到本mysql伺服器,所以應該註釋掉該引數 -
新增埠
-
新增
3306
埠firewall-cmd --zone=public --add-port=3306/tcp --permanent;
-
檢視防火牆狀態
systemctl status firewalld
-
開啟防火牆
systemctl start firewalld
-
重新啟用
3306
埠firewall-cmd --zone=public --add-port=3306/tcp --permanent;
-
重啟防火牆
firewall-cmd --reload
收尾動作
-
檢視
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
-
在
vim /etc/my.cnf
中[mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'
-
預設配置檔案路徑
/etc/my.cnf #這是mysql的主配置檔案 /var/lib/mysql #mysql資料庫的資料庫檔案存放位置 /var/log mysql #資料庫的日誌輸出存放位置