Linux下的MySQL數據庫編程-第二章linux下的數據庫

1、mysql數據庫的安裝python

  能夠經過官方網站下載最新的版本 https://dev.mysql.com/downloads/repo/yum/ ,目前最新版本是mysql8.0,這裏就以mysql8.0安裝爲例。mysql

  系統環境centos7sql

   安裝mysql數據庫數據庫

[root@ceshi-1 ~]# mkdir /usr/local/mysql     #在/usr/local目錄下建立mysql目錄
[root@ceshi-1 ~]# cd /usr/local/mysql/       #進入mysql目錄
[root@ceshi-1 mysql]# wget localinstall https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm   #下載mysql官方rpm
[root@ceshi-1 mysql]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm #安裝軟件,其中i表示安裝,v表示顯示安裝過程,h表示顯示進度
[root@ceshi-1 mysql]# yum install mysql-community-server  #安裝mysql

  目錄說明:centos

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

  

2、mysql初始化配置socket

   一、啓動mysqld服務,並設爲開機自動啓動 網站

[root@ceshi-1 etc]# systemctl start mysqld.service       #啓動mysql
[root@ceshi-1 etc]# systemctl enable mysqld.service      #開機自動啓動mysql

  二、mysql在安裝後會建立一個root@locahost帳戶,而且把初始的密碼放到了/var/log/mysqld.log文件中 加密

[root@ceshi-1 etc]# cat /var/log/mysqld.log | grep password
2019-08-18T08:51:31.405898Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fqNlhhi_j2yb 

  三、登陸mysqlcentos7

[root@ceshi-1 etc]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.17

  四、修改mysql的密碼 (ALTER USER "root"@"localhost" IDENTIFIED BY "你設置的密碼";)spa

[root@ceshi-1 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 8.0.17 MySQL Community Server - GPL

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> ALTER USER "root"@"localhost" IDENTIFIED BY "@Abc456789";
Query OK, 0 rows affected (0.01 sec)

mysql>

  到此mysql就能夠正常使用了。

3、mysql遠程經過navicat訪問

一、下載navicat,到官網下載https://www.navicat.com.cn

二、開啓mysql的遠程訪問。

1,登進MySQL以後, mysql> 2,輸入如下語句,進入mysql庫: mysql>use mysql; 3,更新域屬性,'%'表示容許外部訪問: update user set host='%' where user ='root'; 4,執行以上語句以後再執行: FLUSH PRIVILEGES; 5,再執行受權語句: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; 而後外部就能夠經過帳戶密碼訪問了。(若是navicat不能鏈接成功,多是你的navicat不是版本12以上,12如下的版本在mysql8.0會有一個密碼兼容性問題)
 

 用Navicat12版本如下鏈接mysql,報錯以下:

Client does not support authentication protocol requested by server;
報錯緣由:

mysql8.0 引入了新特性 caching_sha2_password;這種密碼加密方式Navicat 12如下客戶端不支持;

Navicat 12如下客戶端支持的是mysql_native_password 這種加密方式

解決辦法:

mysql>use mysql;

mysql>update user set plugin='mysql_native_password' where user='root'; .

另:若是仍是不能鏈接,能夠檢查如下防火牆設置。

相關文章
相關標籤/搜索