[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
error: '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
命令如下:
但是同樣報錯:error: 'Access denied for user 'root'@'localhost' (using password: NO)',需要像前面一樣修訂密碼,代碼如下:
三. 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>命令如下: create table student(id int not null primary key,name varchar(16) not null,pwd varchar(20) not null );
命令: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语句基础知识的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【python数据挖掘课程】二十二.Ba
- 下一篇: [CentOS Python系列] 四.