程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Learning notes on introduction to Python development: MySQL installation and basic principles

編輯:Python

The point of this section

  • master mysql Installation 、 start-up 、 Crack the code 、 Uniform character encoding

The duration of this section needs to be controlled 15 Within minutes

One 、MySQL Introduce

MySQL Is a relational database management system , The Swedish MySQL AB Companies to develop , At present belongs to the Oracle A subsidiary company .MySQL The most popular relational database management system , stay WEB Application aspect MySQL It's the best RDBMS (Relational Database Management System, Relational database management system ) One of the application software .

mysql What is it?

mysql It's based on socket Compiling C/S Architecture software
Client software
mysql Bring their own : Such as mysql command ,mysqldump Orders, etc
python modular : Such as pymysql

Database management software classification

 There are two main categories :
Relational type : Such as sqllite,db2,oracle,access,sql server,MySQL, Be careful :sql Statement common
Non relational :mongodb,redis,memcache
It can be simply understood as :
Relational databases need to have a table structure
A non relational database is key-value Stored , There is no table structure

Two 、 Download and install

Linux edition

# Binary system rpm Package installation
yum -y install mysql-server mysql

Source code installation see :http://www.cnblogs.com/linhaifeng/articles/7126847.html

Window edition

#1、 download :MySQL Community Server 5.7.16
http://dev.mysql.com/downloads/mysql/
#2、 decompression
If you want to MySQL Install in the specified directory , Then move the unzipped folder to the specified directory , Such as :C:\mysql-5.7.16-winx64
#3、 Add environment variables
【 Right click the computer 】--》【 attribute 】--》【 Advanced system setup 】--》【 senior 】--》【 environment variable 】--》【 Find... In the second content box A variable called Path A line , double-click 】 --> 【 take MySQL Of bin The directory path is appended to the variable value , use ; Division 】
#4、 initialization
mysqld --initialize-insecure
#5、 start-up MySQL service
mysqld # start-up MySQL service
#6、 start-up MySQL Client and connect MySQL service
mysql -u root -p # Connect MySQL The server

The last step solved some problems , But not completely , Because it's executing 【mysqd】 start-up MySQL Server time , The current terminal will be hang live , Then make a setting to solve this problem , the MySQL Service production into windows service

 Be careful :--install front , Must use mysql The absolute path to the start command
# Make MySQL Of Windows service , Execute this command at the terminal :
"c:\mysql-5.7.16-winx64\bin\mysqld" --install
# remove MySQL Of Windows service , Execute this command at the terminal :
"c:\mysql-5.7.16-winx64\bin\mysqld" --remove
After registering as a service , Turn it on and off later MySQL The service , Simply execute the following command :
# start-up MySQL service
net start mysql
# close MySQL service
net stop mysql

3、 ... and 、MySQL Launch and view

linux View under the platform

[[email protected] ~]# systemctl start mariadb # start-up
[[email protected] ~]# systemctl enable mariadb # Set power on self start
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[[email protected] ~]# ps aux |grep mysqld |grep -v grep # Check the process ,mysqld_safe To start mysql Script file for , Internal calls mysqld command
mysql 3329 0.0 0.0 113252 1592 ? Ss 16:19 0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 3488 0.0 2.3 839276 90380 ? Sl 16:19 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
[[email protected] ~]# netstat -an |grep 3306 # Check the port
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[[email protected] ~]# ll -d /var/lib/mysql # The authority is wrong , Launch unsuccessful , Be careful user and group
drwxr-xr-x 5 mysql mysql 4096 Jul 20 16:28 /var/lib/mysql

You must reset your password using ALTER USER statement before executing this statement.

 installed mysql after , After landing , No matter what command you run , Always prompt this
mac mysql error You must reset your password using ALTER USER statement before executing this statement.
resolvent :
step 1: SET PASSWORD = PASSWORD('your new password');
step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
step 3: flush privileges;

windows The platform can be viewed in the service

3、 ... and 、 Login set password

 In the initial state , Administrators root, The password is empty. , By default, only login from local machine is allowed localhost
Set the password
[[email protected] ~]# mysqladmin -uroot password "123" Set the initial password Because the original password is empty , therefore -p Don't have to
[[email protected] ~]# mysqladmin -uroot -p"123" password "456" modify mysql password , Because there's already a password , So you have to enter the original password to set the new password
Command format :
[[email protected] ~]# mysql -h172.31.0.2 -uroot -p456
[[email protected] ~]# mysql -uroot -p
[[email protected] ~]# mysql With root The user logs on to this machine , The password is empty.

3、 ... and 、 Crack the code

linux Under the platform , There are two ways to crack passwords

Method 1 : Delete authorization Library mysql, Reinitialize

[[email protected] ~]# rm -rf /var/lib/mysql/mysql # All authorization information is lost !!!
[[email protected] ~]# systemctl restart mariadb
[[email protected] ~]# mysql

Method 2 : Startup time , Skip the authorization Library

[[email protected] ~]# vim /etc/my.cnf #mysql Master profile
[mysqld]
skip-grant-table
[[email protected] ~]# systemctl restart mariadb
[[email protected] ~]# mysql
MariaDB [(none)]> update mysql.user set password=password("123") where user="root" and host="localhost";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> \q
[[email protected] ~]# # open /etc/my.cnf Get rid of skip-grant-table, And then restart
[[email protected] ~]# systemctl restart mariadb
[[email protected] ~]# mysql -u root -p123 # Log in with a new password

windows Under the platform ,5.7 edition mysql, There are two ways to crack passwords :

Mode one

#1 close mysql
#2 stay cmd In the implementation of :mysqld --skip-grant-tables
#3 stay cmd In the implementation of :mysql
#4 The implementation is as follows sql:
update mysql.user set authentication_string=password('') where user = 'root';
flush privileges;
#5 tskill mysqld # or taskkill -f /PID 7832
#6 Restart mysql

Mode two

#1\. close mysql, It can be used tskill mysqld Kill it
#2\. Under the unzip Directory , newly build mysql The configuration file my.ini
#3\. my.ini Content , Appoint
[mysqld]
skip-grant-tables
#4. start-up mysqld
#5. stay cmd Input directly in mysql Sign in , Then operate
update mysql.user set authentication_string=password('') where user='root and host='localhost';
flush privileges;
#6. notes my.ini Medium skip-grant-tables, Then start myqsld, Then you can log in with a new password

Four 、 Uniform character encoding

emphasize : The comments in the configuration file can be in Chinese , But Chinese cannot appear in the configuration item

# stay mysql Under the unzip directory of , newly build my.ini, Then configure
#1\. In execution mysqld On command , The following configuration will take effect , namely mysql Takes effect when the service starts
[mysqld]
;skip-grant-tables
port=3306
character_set_server=utf8
default-storage-engine=innodb
innodb_file_per_table=1
# Unzip the directory
basedir=E:\mysql-5.7.19-winx64
#data Catalog
datadir=E:\my_data # stay mysqld --initialize when , The initial data will be stored in the directory specified here , After initialization , start-up mysql when , I'm going to look for data in this directory
#2\. Global configuration for client commands , When mysql When a client command is executed , The following configuration takes effect
[client]
port=3306
default-character-set=utf8
user=root
password=123
#3\. Only aim at mysql Configuration of this client ,2 In is global configuration , This is only for mysql The local configuration of this command
[mysql]
;port=3306
;default-character-set=utf8
user=egon
password=4573
#!!! without [mysql], Then the user is executing mysql The command is configured with [client] Subject to

Uniform character encoding

#1\. Modify the configuration file
[mysqld]
default-character-set=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
#mysql5.5 above : There's a change in the way it's modified
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
#2\. Restart the service
#3\. View the modification results :
\s
show variables like '%char%'

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved