Posts Tagged 'mysql'

freebsd upgrade mysql client

January 19th, 2010

mysql serve is 5.1.x, and 5.0.x client is, and use phpmyadmin, there is always a hint that version does not match, feeling uncomfortable.
Ports of methods used to upgrade the client, not work, error. 5.1 and 5.0, there is a conflict that can only be removed.
Used portmaster-o databases/mysql51-client mysql-client-5.0.89
No good.
With export CONFLICTS = "After the implementation, or not do. Read
pkg_info mysql \ *
Have
Required by:
php5-mysql-5.2.12
php5-mysqli-5.2.12
Because also ran website, dared to act.
That day, when few people take advantage of Web site, did a delete the old package
# Pkg_delete-f mysql-client-5.0.89
To mysql5.1 client directory
# Cd / usr/ports/databases/mysql51-client
Loading
# Make install clean
. .
. .
Wait. .
Well, look at the version
# Mysql-V
mysql Ver 14.14 Distrib 5.1.42, for portbld-freebsd8.0 (amd64) using 5.2
With portmaster upgrade two components are dependent on the php
# Portmaster php5-mysql php5-mysqli
Wait.
.
Restart apache, better.
Unexpectedly, the installation process, php can be a normal link mysql. Web site correctly, thought that the use of so pkg_delete will delete files, resulting in a state Web site.

Thank hshh

Popularity: 3%

Oracle's merge with the implementation of the replace into mysql

September 2nd, 2009

mysql replace into the dml a statement similar to the insert, but will check the table before the insert unique index or primary key. If it exists, to update operations.
In many applications, this is a very common operation. With this replace into, you can select after a post-judgment do update or insert into a word, is very convenient.

oracle9 later (as if) with merge into, they can fulfill a similar function, sql demo below

  1. merge into qq a
  2. using   (Select ' '2022' ' cname ' company_no, 'cname' company_name from qq where 2 ) rownum <2) b
  3. on   . company_no = b . company_no ) (A. Company_no = b. Company_no)
  4. WHEN   MATCHED THEN
  5.   UPDATE   SET company_name = a . company_name || ' a ' a. company_name = a. company_name | | 'a'
  6. WHEN   NOT MATCHED THEN
  7.   INSERT
  8.     . company_no , a . company_name ) (A. Company_no, a. Company_name)
  9.   VALUES
  10.     . company_no , b . company_name ) ; (B. Company_no, b. Company_name);

Popularity: 26%

mysql inside oracle decode

August 26th, 2009

There is a decode oracle function, by definition, can be transformed into the basis of demand 1,2,3 a, b, c, finally, a default value.

mysql which seems to not have this function. However, other functions can be used to achieve similar results.

IF (expr1, expr2, expr3)
If expr1 is TRUE (expr1 <>; 0 and expr1 <>; NULL), then IF () returns expr2, otherwise it returns expr3. IF () returns a numeric or string value

oracle wording

SELECT decode (ttype, 1, 'a', 2, 'b', 3, 'c', 'd') FROM taba

Can be written in the mysql

SELECT if (ttype = 1, 'a', if (ttype = 2, 'b', if (ttype = 3, 'c', 'd')))
FROM taba

Popularity: 28%

mysql load data infile

May 5th, 2008

How to improve the speed of mysql load data infile <br /> test data 2.5G, a total of 9,427,567 data. Mysql use of large server configuration.
a need to load about 10 minutes.
Construction of the table is used MYISAM, adjusted several session parameter values

SET SESSION 256217728 ; BULK_INSERT_BUFFER_SIZE = 256217728;
SET SESSION 256217728 ; MYISAM_SORT_BUFFER_SIZE = 256217728;

The results are

Query OK, 9427567 rows affected, 1558 warnings (3 min 55.21 sec)
Records: 9427567 Deleted: 0 Skipped: 0 Warnings: 0
You can also google to the

set global 256217728 ; KEY_BUFFER_SIZE = 256217728;
alter table tablename disable keys;

How to load data, which with a backslash (backslash) "\" data <br /> because if you do not specify a FIELDS clause, the default value assumes that you write down the value of the following statements:
FIELDS TERMINATED BY '\ t' ENCLOSED BY "ESCAPED BY '\ \'
So, if your data inside a backslash (backslash) "\", the data will appear truncated problem. This problem occurs if the following fields to write the clause can be
FIELDS TERMINATED BY '\ t' ENCLOSED BY "ESCAPED BY"

How to load different data encoding the original use of the 4.X <br /> the mysql, I select INTO OUTFILE, after only using iconv, or other software to do. Can be found here , but because the data is large, ultraedit software such as Open should be half a day. Fortunately, the new version of mysql you can add a new parameter
CHARACTER SET gbk
GBK my text data is encoded, the data table is utf8, and tested successfully in this way.
How to load only when the insert specific column <br /> such as meta-data table inside more than out. Time load specified in the field to insert the name.

Sample code is as follows:

LOAD DATA INFILE ' '~ / Data.txt'
INTO TABLE fb0505
CHARACTER SET   gbk
FIELDS TERMINATED BY ' '\ T' ENCLOSED BY '' ESCAPED BY ''
LINES TERMINATED BY ' '\ N' STARTING BY ''
, fb_type , fb_date , item_url ) ; (Seller_id, fb_type, fb_date, item_url);

In which there is also a table fb0505 is id.

Popularity: 27%

mysql code to remove special asc

July 22nd, 2007

To do a mysql data import and update of the work. Data source is excel in the past.
Select the top left corner of the element inside excel, ctrl + shift + end, select all of a content cell. Save the file as a abc.txt.
Data only 2 columns, built a 2 column table, ready to load into the data, with root user logged in the shell run the following command mysql
load data infile '/ root / test.dat' into table mytable FIELDS TERMINATED BY '\ t';
Results of error.
ERROR 13 (HY000): Can't get stat of '/ root / test.dat' (Errcode: 13)
Then google, that is the question of powers, it seems likely that mysql can not read the document root directory, which was replaced with the one directory, problem-solving.
load data infile '/ tmp / test.dat' into table ppname FIELDS TERMINATED BY '\ t';
But then the problems, the basic let me crash.
Example

select * from mysql> select * from mytable;
+------+------+
| b | | A | b |
+------+------+
| aaa | Aaa | aaa
+------+------+
1 row in set (0.00 sec)

The naked eye looks, a and b are the same, then I like to match in accordance with strange is how to do it will not work at first thought it was the case in question, made a lower operation does not work.
Was beginning not to trust your eyes, look in the end what is

select mysql> select a ) , hex ( b ) hex (a), hex (b) from mytable;
+--------+----------+
( a ) | hex ( b ) | | Hex (a) | hex (b) |
+--------+----------+
| 6161610 D | | 616161 | 6161610 D |
+--------+----------+
1 row in set (0.00 sec)

This time only to find the back of each character more than a
0D
Was the question came up for an hour, frustrated to death. Do the following treatment, the clouds finally cleared to see the Sun.
update mytable set b = UNHEX (TRIM (TRAILING '0 D 'FROM hex (b)));

The strange thing is I do not come out of this simulated data, originally thought it was not added to "LINES TERMINATED BY '\ n'" problem, but no line was added,: S
It seems eBay item ah.

Popularity: 17%

Analysis with mysqldumpslow mysql's slow query log

June 7th, 2007

mysql has a function that can log down and run slower sql statement, the default is not the log, in order to enable this feature, to modify the my.cnf or mysql startup add some parameters. If you modify the my.cnf which is required to add the following lines

long_query_time = 1
log-slow-queries = / var / youpath / slow.log
log-queries-not-using-indexes

long_query_time is over how long the sql execution log will be down, here is 1 second.
log-slow-queries set to log written there can be empty, the system will give a default file host_name-slow.log, I generated the data log directory in mysql
log-queries-not-using-indexes is the literal meaning, log off do not use the index query.

Open the above parameters, run time, you can turn off the backs with affected production environment.

The next step is analysis, I have here a document called host-slow.log.
Following the first mysqldumpslow-help, I mainly used the
-S ORDER what to sort by (t, at, l, al, r, ar etc), 'at' is default
-T NUM just show the top n queries
-G PATTERN grep: only consider stmts that include this string

-S, is the order of the sequence, indicating not written in detail, I use down, including reading the code, mainly
c, t, l, r and ac, at, al, ar, respectively, in accordance with the query frequency, time, lock time and return the number of records to sort, preceded by the time a flashback
-T, is the top n means, that is, how many return to the previous data
-G, the back can write a regular pattern matching, case insensitive

mysqldumpslow-sc-t 20 host-slow.log
mysqldumpslow-sr-t 20 host-slow.log

The command can be seen up to 20 visits sql statement and return records set up to 20 sql.
mysqldumpslow-t 10-st-g "left join" host-slow.log
This is in accordance with the time to return to the previous 10 which connect the sql statement with the left.

Using this tool you can check out which sql statement is performance bottleneck, optimize, such as the index increases, the realization of the application methods.

Popularity: 30%

apache child pid exit signal File size limit exceeded error

May 25th, 2007

A normal use of the site, LAMP architecture, suddenly could not open, but the other two domain sites on the same server can open, static documents can be opened because the failure for some time before the program is not updated, the program error is unlikely.
telnet to port 80 web site, you can also open, very strange phenomenon.
Restart the apache, useless, mysql command line can also be used, no problem, sometimes not the right direction.
Then tail the apache's log, a is a normal web log, a is the error_log.
Observation, and found the anomaly, apache's error_log has output an error message as follows:

[Thu May 24 23:11:27 2007] [notice] child pid 23406 exit signal File size limit exceeded (25)
[Thu May 24 23:12:01 2007] [notice] child pid 23544 exit signal File size limit exceeded (25)
[Thu May 24 23:12:47 2007] [notice] child pid 23633 exit signal File size limit exceeded (25)
[Thu May 24 23:12:53 2007] [notice] child pid 22799 exit signal File size limit exceeded (25)

That there are file size exceeds the limit.
google a bit, saying that more than apache 2G file limit, find the command in the system try to find large files inside

find /-size +1000000 k

Find two files, one is

/ Xxx / xxx / page_parse_time.log
/ Xxx / yyy / support-popbytes_log

The first file page_parse_time.log about the size of the 2G, compressed backup,

> / Xxx / xxx / page_parse_time.log

To solve the problem.
page_parse_time.log contents of the file is sql query in the log record program and the execution time of the log, will be written on every page request some data, so no wonder that more than 2G.

Last mysql data also encountered a few too many articles, the problem error message as follows:

LOGSQL Insert insert Failed: insert into adodb_logsql , sql0 , sql1 , params , tracer , timer ) (Created, sql0, sql1, params, tracer, timer) values ( ,?,?,?,?,? ) NOW () ,?,?,?,?,?) The table ' 'Adodb_logsql' is full

By Charles

select mysql> select * ) count (*) from adodb_logsql;
+----------+
( * ) | | Count (*) |
+----------+
| | 33127244 |
+----------+

3 million,,, may be a bit bigger, and finally truncate this table, problem solving, but the final document search mysql, Scalability and Limits on the part of mysql did not say how many records kept up to the estimated type is also associated with the table. Text that is
Handles large databases. We use MySQL Server with databases that contain 50 million records. We also know of users who use MySQL Server with 60,000 tables and about 5,000,000,000 rows.
Just do not know it says 50 million which is a database of all records or records of all the tables together. Behind the table should be combined for all 60,000 data.
--------
Conclusion, the necessary logs are needed, but to control the size, there are circulation mechanism, or a monitoring mechanism, remember, remember.

Popularity: 31%

discuz mysql database data conversion latin1-> utf8

March 13th, 2007

Forum to help a friend do a data conversion work. System is windows 2003, mysql4.1 discuz 5
Originally thought is very simple, dump the data
mysqldump-u root-p-opt-default-character-set = latin1 \
-Skip-set-charset olddb cdb_members> d: \ bak \ cdb_members.sql
Out what code to use tools to turn, and then import
mysql-u root-p-default-character-set = utf8 newdb <d: \ bak \ cdb_members.sql

Practice is not so easy, the final solutions, not that complicated.
»More: discuz mysql database data conversion latin1-> utf8

Popularity: 30%

mysql tips

March 10th, 2007
  • Run in a text file in the sql statement

shell> mysql db_name <text_file

You can also start with a USE db_name statement in a text file. In this case, do not need to specify the database name on the command line:

shell> mysql <text_file

If you are running mysql, you can use the source or \. Command execution SQL script file:

mysql> source filename

mysql> \. filename

Popularity: 16%