Introduction Using the mysql Client Program

1.1 Introduction

The MySQL dat abase syst em uses a client - server archit ect ure t hat cent ers around t he server, m ysqld. The server is t he program t hat act ually m anipulat es dat abases. Client program s dont do t hat direct ly; rat her, t hey com m unicat e your int ent t o t he server by m eans of queries writ t en in St ruct ured Query Language SQL . The client program or program s are inst alled locally on t he m achine from which you wish t o access MySQL, but t he server can be inst alled anywhere, as long as client s can connect t o it . MySQL is an inherent ly net worked dat abase syst em , so client s can com m unicat e wit h a server t hat is running locally on your m achine or one t hat is running som ewhere else, perhaps on a m achine on t he ot her side of t he planet . Client s can be writ t en for m any different purposes, but each int eract s wit h t he server by connect ing t o it , sending SQL queries t o it t o have dat abase operat ions perform ed, and receiving t he query result s from it . One such client is t he m ysql program t hat is included in MySQL dist ribut ions. When used int eract ively, m ysql prom pt s for a query, sends it t o t he MySQL server for execut ion, and displays t he result s. This capabilit y m akes m ysql useful in it s own right , but it s also a valuable t ool t o help you wit h your MySQL program m ing act ivit ies. I t s oft en convenient t o be able t o quickly review t he st ruct ure of a t able t hat youre accessing from wit hin a script , t o t ry a query before using it in a program t o m ake sure it produces t he right kind of out put , and so fort h. m ysql is j ust right for t hese j obs. m ysql also can be used non- int eract ively, for exam ple, t o read queries from a file or from ot her program s. This allows you t o use it from wit hin script s or cr on j obs or in conj unct ion wit h ot her applicat ions. This chapt er describes m ysqls capabilit ies so t hat you can use it m ore effect ively. Of course, t o t ry out for yourself t he recipes and exam ples shown in t his book, youll need a MySQL user account and a dat abase t o work wit h. The first t wo sect ions of t he chapt er describe how t o use m ysql t o set t hese up. For dem onst rat ion purposes, t he exam ples assum e t hat youll use MySQL as follow s: • The MySQL server is running on t he local host . • Your MySQL usernam e and password are cbuser and cbpass . • Your dat abase is nam ed cookbook . For your own experim ent at ion, you can violat e any of t hese assum pt ions. Your server need not be running locally, and you need not use t he usernam e, password, or dat abase nam e t hat are used in t his book. Nat urally, if you dont use MySQL in t he m anner j ust described, youll need t o change t he exam ples t o use values t hat are appropriat e for your syst em . Even if you do use different nam es, I recom m end t hat you at least creat e a dat abase specifically for t rying t he recipes shown here, rat her t han one youre using current ly for ot her purposes. Ot herwise, t he nam es of your exist ing t ables m ay conflict wit h t hose used in t he exam ples, and youll have t o m ake m odificat ions t o t he exam ples t hat are unnecessary when you use a separat e dat abase.

1.2 Setting Up a MySQL User Account