The following is an example of the database "Ceshi"
1, connect the database
The code is as follows
Copy Code
Mysql-u username-p Password
2. Create/Delete Database
The code is as follows
Copy
Using on DUPLICATE KEY update
Look at two SQL first
The code is as follows
Copy Code
INSERT into Osc_visit_stats (stat_date,type,id,view_count) VALUES (?,?,?,?) On DUPLICATE KEY UPDATE view_count=view_count+?
MySQL serve is 5.1.x, the client is 5.0.x, with phpMyAdmin, there is always a hint that the version does not match, feeling bad. Use the Ports method to upgrade the client, no, no error. Said 5.1 and 5.0 conflict, can only be deleted first.
Restore a database: mysql-h localhost-u root-p123456 Www
Back up a database: mysqldump-h localhost-u root-p123456 www > d:/www2008-2-26.sql
Backup data:
The code is as follows
Copy Code
Mysqldump-u User name-p password
Re-edit the encoding
First copy a my.cnf to/OPT/LOCAL/ETC/MYSQL5:
The code is as follows
Copy Code
$ cd/opt/local/etc/mysql5/$ sudo cp/opt/local/share/mysql5/mysql/my-small.cnf my.cnf
Then edit my.cnf and add
Solve the problem of garbled web pages, defined in the program query
The code is as follows
Copy Code
db = MySQL _connect ("localhost", "User", "password");mysql_select_db ("message", $db);mysql_query ("SET NAMES ' UTF8 '
Mysqldump Export Command Base usage
The code is as follows
Copy Code
Mysqldump-u username-P [--opt] DATABASENAME [Table] > Export SQL file name
The default mysqldump exported SQL file contains not only the
COUNT (*) calculates the number of rows, including null
Count (column) calculates the number of rows for a particular column's value, and does not contain null values.
Count () is also used, and the use of Count (1) is the same as the result of
The following query selects all records and its date_col value is within the last 30 days:
The code is as follows
Copy Code
Mysql> SELECT something from tableWHERE To_days (now ())-To_days (Date_col)
DayOfWeek
One, time lag
DateDiff: To put it bluntly is to use the first time to reduce the second time, the order can not forget
The code is as follows
Copy Code
Select DateDiff (' 2012-08-08 ', ' 2012-08-13 '); ---5
First, the way to start
1, use service to start: Service mysqld start
2. Start with mysqld script:/etc/init.d/mysql start
3. Use Safe_mysqld to start:safe_mysqld&
Second, stop
1, use service to start: Service mysqld stop
2. Start with mysqld
On Weibo, see @ Jinshan mentions a performance problem in MySQL,
The code is as follows
Copy Code
Select ID from table where ID > M ID
Which is faster?
There are three kinds of query conditions here:
Backup data:
The code is as follows
Copy Code
Mysqldump-u User name-p password database name > Xx.sql
When the volume of data is large, you can use gzip compression
The code is as follows
Copy
There are 2 ways to resolve this problem:
localhost change to%
Go to MySQL Bin directory
The code is as follows
Copy Code
Mysql-u root-pMysql>use MySQL;Mysql>update User Set host = '% ' where user = ' root
Compare with mysqldump:
1, the former is a fast file in the sense of copy, the latter is a database-side SQL statement collection.2, the former can only run in the database directory on the machine, the latter may be used in remote clients, but the
Symptoms of damage
A typical symptom of a damaged table is as follows:1. When selecting data from a table, you get the following error: Incorrect key file for table: ' ... '. Try to repair it2. The query cannot find rows in the table or return
MySQL Query Cache defaults to open. To a certain extent can improve the effect of the query, but not necessarily the best solution, if there are a large number of modifications and queries, due to the cache failure caused by the modification, the
LTrim function
The code is as follows
Copy Code
Mysql> Select Concat ('. ', LTrim (' ddd '), '. ');
RTrim function
The code is as follows
Copy Code
Mysql> Select Concat ('. ', RTrim
$ Hostname = "localhost"; // defines the name of the connected mysql server$ Username = "root"; // defines the user name used for connection.$ Password = ""; // defines the password used for connection.$ Link = mysql_connect ($ hostname, $ username,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service