日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

[CentOS Python系列] 三.阿里云MySQL数据库开启配置及SQL语句基础知识

發布時間:2024/6/1 数据库 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [CentOS Python系列] 三.阿里云MySQL数据库开启配置及SQL语句基础知识 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

從2014年開始,作者主要寫了三個Python系列文章,分別是基礎知識、網絡爬蟲和數據分析。

  • Python基礎知識系列:Pythonj基礎知識學習與提升
  • Python網絡爬蟲系列:Python爬蟲之Selenium+Phantomjs+CasperJS
  • Python數據分析系列:知識圖譜、web數據挖掘及NLP

??

隨著人工智能和深度學習的風暴來臨,Python變得越來越火熱,作者也準備從零學習這些知識,寫相關文章。本篇文章講解阿里云服務器CentOS系統下的MySQL數據庫開啟及配置過程,同時教大家如何編寫Python操作MySQL數據庫的基礎代碼,為后面的網絡爬蟲并存儲至服務器打下基礎。

文章非常基礎,希望這系列文章對您有所幫助,如果有錯誤或不足之處,還請海涵~

系列文章:
[CentOS Python系列] 一.阿里云服務器安裝部署及第一個Python爬蟲代碼實現
[CentOS Python系列] 二.pscp上傳下載服務器文件及phantomjs安裝詳解

參考文獻:
基于CentOS的Mysql的使用說明 - chisj專欄



一. MySQL數據庫開啟

1.檢查數據庫是否安裝

命令:rpm -qa | grep mysql



2.檢查MySQL服務是否開啟

命令:service mysqld status



3.開啟MySQL服務

命令:service mysqld start


可以看到 /usr/bin 目錄下存在mysqladmin命令。





4.使用root用戶登錄mysql數據

命令:mysqladmin -u root -p password 123456


但是報如下錯,這是連接MySQL數據庫最常見的一個錯誤,怎么解決呢?
mysqladmin: connect to server at 'localhost' failed
e
rror: 'Access denied for user 'root'@'localhost' (using password: NO)'


5.更新root密碼登錄

命令如下:

--關閉服務 service mysqld stop--安裝賦權限 mysqld_safe --skip-grant-tables &--root用戶登錄 mysql -u root -p --輸入密碼 123456--使用數據庫 use mysql;--更新密碼 update user set password=PASSWORD("123456") where user="root";--更新權限 flush privileges; --退出 quit--服務器重啟 service mysqld restart--root用戶登錄 mysql -u root -p 新密碼進入 如下圖所示:


然后輸入“use mysql;”使用數據庫,嘗試“show databases;”顯示所有數據庫。



接下來就是更新root用戶的密碼:


6.重啟服務本地連接mysql數據庫

命令:service mysqld restart
? ? ? ? ? mysql -u root -p






二. MySQL數據庫增加新用戶

1.使用mysql數據庫

命令:use mysql;



2.顯示所有表

命令:show tables;

這里我們使用user表,定義mysql數據庫的用戶。



3.查看表結構

命令:describe user;

| Host | char(60) | NO | PRI | | | | User | char(16) | NO | PRI | | | | Password | char(41) | NO | | | |
4.添加一個新用戶yxz,密碼為123456

命令如下:

mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> insert into mysql.user(Host,User,Password) value ("localhost","yxz",password("123456")); Query OK, 1 row affected, 3 warnings (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)mysql> create database Eastmount; Query OK, 1 row affected (0.00 sec)mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | Eastmount | | junyun | | mysql | | test | +--------------------+ 5 rows in set (0.00 sec)mysql> grant all privileges on Eastmount.* to yxz@localhost identified by "yxz"; Query OK, 0 rows affected (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)mysql>quit; 如下圖所示:

但是同樣報錯:error: 'Access denied for user 'root'@'localhost' (using password: NO)',需要像前面一樣修訂密碼,代碼如下:

[root@iZ2ze9134z8zlqupc9t6mzZ ~]# service mysqld stop Stopping mysqld: [ OK ] [root@iZ2ze9134z8zlqupc9t6mzZ ~]# mysqld_safe --skip-grant-tables & [1] 24403 [root@iZ2ze9134z8zlqupc9t6mzZ ~]# 180217 13:50:37 mysqld_safe Logging to '/var/log/mysqld.log'. 180217 13:50:37 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql mysql -u yxz -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | Eastmount | | junyun | | mysql | | test | +--------------------+ 5 rows in set (0.00 sec)mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql> update user set password=PASSWORD("123456") where user="yxz"; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)mysql> quit;


三. SQL語句

1.root登錄并進入Eastmount數據庫

命令如下:

[root@iZ2ze9134z8zlqupc9t6mzZ ~]# mysql -u yxz -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | Eastmount | | test | +--------------------+ 3 rows in set (0.00 sec)mysql> use Eastmount; Database changed mysql> show tables; Empty set (0.00 sec)mysql>


2.創建表
命令如下:
create table student(id int not null primary key,name varchar(16) not null,pwd varchar(20) not null );


3.顯示表結構

命令:describe student;



4.插入數據

命令:insert into student(id,name,pwd) values(1,'yxz','111111');


5.查詢數據

命令:select * from student;



6.更新數據

命令:update student set pwd='123456' where name='yxz';



7.刪除數據

命令:delete from student where id='1';



8.刪除表

命令:drop table studentl;




總之,希望這篇基礎文章對您有所幫助,尤其是剛接觸云服務器的新手,如果您是高手,還請多提意見,共同提高。祝大家新年快樂,又一年過去了,娜我們來年一起進步加油。?
( By:Eastmount CSDN 2018-02-13 中午12點?http://blog.csdn.net/Eastmount?)



總結

以上是生活随笔為你收集整理的[CentOS Python系列] 三.阿里云MySQL数据库开启配置及SQL语句基础知识的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。