25.1 MySQL Database
/*
But I didn't prompt for the password when I installed it on the virtual machine.
This can refer to http://blog.csdn.net/sinat_21302587/article/details/76870457
Cause login without knowing the account password.
The default account password is on the/etc/mysql/debian.cnf. For example,user and password are account passwords . Then you can log in.
The way to restart/open/close MySQL is: sudo service MySQL restart/start/stop
*/
1. I'm just faking it (on the company's server):
$sudo Apt-get Install Mysql-server
Then you will be prompted to lose the password (there will be an interface out), I lost here is 123456.
Problem: Build a table in MySQL to prompt such errors error 1046 (3d000): No Database Selected How to solve???
Workaround:
Build the database first and use it.
Create DATABASE MyTest
Use MyTest
CREATE TABLE XCYTB (ID int, name varchar (30));
2. The following describes an automatic login method that is tested on my virtual machine.
As previously stated, the account password is in/etc/mysql/debian.cnf. And the account password is particularly difficult to remember. Our purpose is to log in directly from the command line by entering MySQL.
Reference: http://www.jb51.net/article/116488.htm
1) Create a new directory in the home directory. My.cnf. The format is as follows:
[Client]
Password=your_pass
User=your_user
2) Change permissions chmod. my.cnf. (I later changed it to 777 permission to log in)
3) Enter MySQL on the command line to log in. Such as:
25.1.1 using MySQL
1. Connect to the server
The above has been introduced.
2.MySQL command
For beginners, it is necessary to understand the basics of relational databases. Here are just a few commands to write about.
; Semicolon indicates the end of the command
1) Show command: Can be used to extract information about the MySQL server
show databases; Displays the servers currently configured on the MySQL server.
Use DatabaseName; Connect a single database . MySQL session can only connect to one database at a time
Show tables; Displays the tables on the connected database. The database needs to be connected first
3. Create a Database
Create databases MyTest;
Then you can check
show databases;
Then connect to the database you just created
Use mytest;
You can then create a table, and then make a search for additional deletions.
4. Create a user account
We already know how to connect to the MySQL server with the root administrator account. This account has full control over all MySQL server objects (just like Linux's root account can fully control the Linux system)
It's more dangerous.
You need to create a separate user account on MySQL that has permissions on only the databases involved in the app.
Statement: The GRANT SQL statement can be completed
mysql> GRANT select,insert,delete,update, on mytest.*-to-test identified by ' test ';
Error 1064 (42000): You have a error in your SQL syntax; Check the manual, corresponds to your MySQL server version for the right syntax to use near ' on mytest.* to test IDENT ified by ' test ' on line 1
Just like the yellow highlight above, the book is so written, but I run the error, do not know what the reason.
For Grant you can refer to this:
Https://www.cnblogs.com/hcbin/archive/2010/04/23/1718379.html
CREATE table Delete table later insert data delete data Update data similar to Sqlite3, someone reads it again.
25.1.2 using a database in a script
25.2 using the Web
The Lynx program allows you to access the site directly from a terminal session. But the picture will be replaced with a label.
The Lynx command-line command and its expertise in extracting information from remote Web sites.
25.3 using e-mail
The primary tool that can be used to send e-mail from shell scripts is the MAILX program. Not only can you use it to read and send messages interactively, but you can also specify how messages are sent with command-line arguments
The command-line format for sending messages to the MAILX program is:
main [-EIINV] [-A header] [-B addr] [-C addr] [-s subj] To-addr
About using e-mail:
1. On the company server
sudo apt-get install mailutils
There will be some configuration (interface) in this installation. I don't know much either. Just look at the configuration for a bit.
Then you can send it. (Sent to others or not received)
[Email protected]:~/\u684c\u9762/xcynote$ echo "test,hahah222" | Mail-s "Xcytest" Xiaochongyong
[Email protected]:~/\u684c\u9762/xcynote$ Mail
"/var/mail/xiaochongyong": 1 message 1 new
>n 1 Xiaochongyong \u4e00 12\u6708 4 10:13/471 xcytest
?
Return-path: <[email protected]>
x-original-to: [Email protected]
delivered-to: [Email protected]
Received:by Sam-server (Postfix, from UserID 1011)
ID 296b35e024e; Mon, 4 Dec 10:12:41 +0800 (CST)
Subject:xcytest
To: <[email protected]>
X-mailer:mail (GNU mailutils 2.99.98)
Message-id: <[email protected]>
Date:mon, 4 Dec 10:12:41 +0800 (CST)
From: [Email protected] (Xiaochongyong)
test,hahah222
?
No applicable message
? Quit
Saved 1 Message In/home/xiaochongyong/mbox
Held 0 Messages In/var/mail/xiaochongyong
[Email protected]:~/\u684c\u9762/xcynote$
2. On my virtual machine
sudo apt-get install mailutils
There is no configuration at the time of installation. After the direct send, the result is error:
[Email protected]:~$ echo "Hahah,test" | Mail-s "Test"[email protected]
Mail:cannot send Message:process exited with a Non-zero status
Then refer to: http://mars914.iteye.com/blog/1470961
Then installed the
sudo apt-get install SendMail
sudo apt-get install SENDMAIL-CF
sudo apt-get install sharutils
Then send:
[Email protected]:~$ echo "hahaha" | Mail-s "Testxcy"[email protected]
[Email protected]:~$ echo "HAHAHA2" | Mail-s "Testxcy"[email protected]
[Email protected]:~$ echo "HAHAHA2" | Mail-s "Testxcy" Xcy
[Email protected]:~$
It runs very long each time. It looks like an error. An mbox file was logged in the home directory, and some information was recorded.
[Email protected]:/etc/mail$ Mail
"/var/mail/xcy": 3 Messages 3 new
>n 1 Mail Delivery Subs December 4 09:65/2297 returned Mail:see TRANSC
N 2 Mail Delivery Subs December 4 10:65/2297 returned Mail:see TRANSC
N 3 Xcy December 4 10:15/607 testxcy
?
Return-path: <MAILER-DAEMON>
Received:from localhost (localhost)
by Xcy-virtual-machine (8.14.4/8.14.4/DEBIAN-4.1UBUNTU1) ID vb41npsx0083
15;
Mon, 4 Dec 2017 09:49:25 +0800
Date:mon, 4 Dec 2017 09:49:25 +0800
From:mail Delivery Subsystem <MAILER-DAEMON>
Message-id: <[email protected]>
To: <[email protected]>
mime-version:1.0
Content-type:multipart/report; Report-type=delivery-status;
boundary= "Vb41npsx008315.1512352165/xcy-virtual-machine"
subject:returned Mail:see Transcript for details
Auto-submitted:auto-generated (Failure)
This is a mime-encapsulated message
--vb41npsx008315.1512352165/xcy-virtual-machine
The original message was received at Mon, 4 Dec 2017 09:48:22 +0800
from localhost [127.0.0.1]
-----The following addresses had permanent fatal errors-----
<[email protected]>
(reason:550 Failed to connect remote host.)
-----Transcript of Session follows-----
... while talking to mx3.qq.com.:
<<< 550 Failed to connect remote host.
... while talking to mx2.qq.com.:
<<< 550 Failed to connect remote host.
So the machine was restarted a bit. You can do it.
[Email protected]:/var/mail$ Echo]20171204tete" | Mail-s "TEst2"Xcy
[Email protected]:/var/mail$ Mail
"/var/mail/xcy": 3 messages 1 new 2 unread
U 1 Mail Delivery Subs December 4 10:68/2341 returned Mail:see TRANSC
U 2 xcy December 4 10:17/626 testxcy
>n 3 Xcy December 4 10:15/610 test2
?
Return-path: <[email protected]>
Received:from xcy-virtual-machine (localhost [127.0.0.1])
by Xcy-virtual-machine (8.14.4/8.14.4/DEBIAN-4.1UBUNTU1) with ESMTP ID vb42yuhw003098
For <[email protected]>; Mon, 4 Dec 2017 10:34:56 +0800
Received: (from [email protected])
by Xcy-virtual-machine (8.14.4/8.14.4/submit) ID vb42yuqw003093;
Mon, 4 Dec 2017 10:34:56 +0800
Date:mon, 4 Dec 2017 10:34:56 +0800
From:xcy <[email protected]>
Message-id: <[email protected]>
Subject:test2
To: <[email protected]>
X-mailer:mail (GNU mailutils 2.99.98)
20171204tete
?
No applicable message
?
But it can't be sent to others.
The 25th chapter of the Linux command line and shell scripting Encyclopedia creates scripts related to databases, web, and e-mail