Problem Solution Discussion Starting and Terminating mysql

| centipede | 100 | 0 | | table | 4 | 0 | | armchair | 4 | 2 | | phonograph | 0 | 1 | | tripod | 3 | 0 | | Peg Leg Pete | 1 | 2 | | space alien | NULL | NULL | +--------------+------+------+ 12 rows in set 0.00 sec At t his point , youre all set up wit h a dat abase and a t able t hat can be used t o run som e exam ple queries.

1.4 Starting and Terminating mysql

1.4.1 Problem

You want t o st art and st op t he m ysql program .

1.4.2 Solution

I nvoke m ysql from your com m and prom pt t o st art it , specifying any connect ion param et ers t hat m ay be necessary. To leave m ysql, use a QUIT st at em ent .

1.4.3 Discussion

To st art t he m ysql program , t ry j ust t yping it s nam e at your com m and- line prom pt . I f m ysql st art s up correct ly, youll see a short m essage, followed by a mysql prom pt t hat indicat es t he program is ready t o accept queries. To illust rat e, heres what t he welcom e m essage looks like t o save space, I wont show it in any furt her exam ples : mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18427 to server version: 3.23.51-log Type help; or \h for help. Type \c to clear the buffer. mysql I f m ysql t ries t o st art but exit s im m ediat ely wit h an access denied m essage, youll need t o specify connect ion param et ers. The m ost com m only needed param et ers are t he host t o connect t o t he host where t he MySQL server runs , your MySQL usernam e, and a password. For exam ple: mysql -h localhost -p -u cbuser Enter password: cbpass I n general, I ll show m ysql com m ands in exam ples wit h no connect ion param et er opt ions. I assum e t hat youll supply any param et ers t hat you need, eit her on t he com m and line, or in an opt ion file Recipe 1.5 so t hat you dont have t o t ype t hem each t im e you invoke m ysql. I f you dont have a MySQL usernam e and password, you need t o obt ain perm ission t o use t he MySQL server, as described earlier in Recipe 1.2 . The synt ax and default values for t he connect ion param et er opt ions are shown in t he following t able. These opt ions have bot h a single-dash short form and a double-dash long form . Pa r a m e t e r t ype Opt ion syn t a x for m s D e fa u lt va lu e Host nam e - h hostname - - host = hostname localhost Usernam e - u username - - user = username Your login nam e Password - p- - password None As t he t able indicat es, t here is no default password. To supply one, use - - password or -p, t hen ent er your password when m ysql prom pt s you for it : mysql -p Enter password: enter your password here I f you like, you can specify t he password direct ly on t he com m and line by using eit her - p password not e t hat t here is no space aft er t he -p or - - password = password . I dont recom m end doing t his on a m ult iple- user m achine, because t he password m ay be visible m om ent arily t o ot her users who are running t ools such as ps t hat report process inform at ion. I f you get an error m essage t hat m ysql cannot be found or is an invalid com m and when you t ry t o invoke it , t hat m eans your com m and int erpret er doesnt know where m ysql is inst alled. See Recipe 1.8 . To t erm inat e a m ysql session, issue a QUIT st at em ent : mysql QUIT You can also t erm inat e t he session by issuing an EXIT st at em ent or under Unix by t yping Ct r l- D. The way you specify connect ion param et ers for m ysql also applies t o ot her MySQL program s such as m ysqldum p and m ysqladm in. For exam ple, som e of t he act ions t hat m ysqladm in can perform are available only t o t he MySQL root account , so you need t o specify nam e and password opt ions for t hat user: mysqladmin -p -u root shutdown Enter password:

1.5 Specifying Connection Parameters by Using Option Files