MySQL database starts to automatically execute a command (using init-file)

Source: Internet
Author: User

Usage example of the init-file option of MySQL

Init-file is the script loaded when MySQL is started.

There are two notes.

1. Make sure that the -- disable-grant-options switch is not added during mysqld compilation.

2. Make sure that each line of the script specified by init-file has a specific statement.

Use the following method to directly add it to the configuration file, such as my. CNF.

Add:

[Server], [mysqld], or [mysqld_safe]

Init-file = "your file location"

# The following options will be passed to all MySQL clients

[Server]

Init-file =/usr/local/mysql567/init. File

[Root @ ambow-School-system-hylm bin] # ll/usr/local/mysql567/init. File

-RW ---- 1 MySQL 92 DEC/usr/local/mysql567/init. File

[Root @ hylm bin] CAT/usr/local/mysql567/init. File

Use test;

Insert Chen select substr (passid, 1, 7) A, max (passid) as AA from user group by;

[Root @ hylm bin] #

Mysql> show create table Chen \ G;

* *************************** 1. row ***************************

Table: Chen

Create Table: Create Table 'chen '(

'Pkey' char (8) default null,

'Value' char (25) default null

) Engine = memory default charset = utf8

1 row in SET (0.00 Sec)

Error:

No query specified

Mysql> show create table user \ G;

* *************************** 1. row ***************************

Table: User

Create Table: Create Table 'user '(

'Passid' char (25) default null

) Engine = MyISAM default charset = utf8

1 row in SET (0.00 Sec)

Error:

No query specified

Mysql> select * from user;

+ ----------------- +

| Passid |

+ ----------------- +

| Apt1212100000 |

| Apt1212100002 |

| Apt1212100003 |

| Cisco1212100001 |

| Cisco1212100002 |

| Cisco1212100003 |

| Tmp1212100001 |

| Tmp1212100002 |

| Tmp1212100003 |

+ ----------------- +

9 rows in SET (0.00 Sec)

Mysql>

After restarting, you can see the following:

Mysql> select * From Chen;

+ --------- + --------------- +

| Pkey | value |

+ --------- + --------------- +

| Apt1212 | apt1212100003 |

| Cisco12 | cisco1212100003 |

| Tmp1212 | tmp1212100003 |

+ --------- + --------------- +

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.