1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
|
<html>
<head>
<title>SQL Relay - Getting Started With MySQL</title>
<link rel="stylesheet" href="../css/styles.css">
</head>
<body>
<span class="heading1">Getting Started With MySQL</span><br>
<ul>
<li><a href="#installation">Installation</a></li>
<ul>
<li><a href="#rpm">RPM-based Linux</a></li>
<li><a href="#debian">Debian Linux</a></li>
<li><a href="#slackware">Slackware Linux</a></li>
<li><a href="#freebsd">FreeBSD</a></li>
<li><a href="#openbsd">OpenBSD</a></li>
<li><a href="#netbsd">NetBSD</a></li>
<li><a href="#openserver">SCO OpenServer</a></li>
<li><a href="#solaris">Solaris</a></li>
<li><a href="#source">Compiling From Source</a></li>
<li><a href="#startingatboot">Starting the Database at Boot Time</a></li>
</ul>
<li><a href="#creating">Creating a Database</a></li>
<li><a href="#accessing">Accessing a Database</a></li>
<li><a href="#sqlrelay">Accessing a Database With SQL Relay</a></li>
<li><a href="#quirks">MySQL Quirks</a></li>
</ul>
<a name="installation"></a>
<span class="heading1">Installation</span><br>
<p>I've sucessfully installed MySQL on Linux, FreeBSD, NetBSD, OpenBSD, SCO
OpenServer and Solaris.</p>
<p>FreeBSD, OpenBSD, NetBSD and most Linux distributions come with MySQL
and give you the option of installing it when you install the rest of the
system. If you want or need to install it afterward, follow the instructions
below.</p>
<a name="rpm"></a>
<span class="heading2">RPM-based Linux</span><br>
<p>To install MySQL on an RPM-based Linux distribution like RedHat,
Mandrake or TurboLinux, acquire the mysql, mysql-server and mysql-devel
RPMS from <a href="http://rpmfind.net">RPMFind</a> or possibly from the CD's
that came with your distribution and install them using <i>rpm -i</i>.</p>
<a name="debian"></a>
<span class="heading2">Debian Linux</span><br>
<p>If you have configured <i>apt</i> as illustrated in
<a href="http://www.debian.org/doc/manuals/apt-howto/index.en.html">the
APT-HOWTO</a>, run <i>apt-get install mysql-server</i> and <i>apt-get install
libmysqlclientclient6-dev</i>. If your distribution came with MySQL, you may
be promted to enter a CD. If not, it will be downloaded from the internet.
When the commands complete, MySQL will be installed. MySQL packages don't
appear to be available for older Debian releases, so for those releases, I've
always compiled it from source. Alternatively, you can download a binary
distribution in tar.gz format from
<a href="http://www.mysql.com/downloads">the MySQL site</a>.</p>
<a name="slackware"></a>
<span class="heading2">Slackware Linux</span><br>
<p>The mysql package is available from
<a href="ftp://ftp.slackware.com">ftp.slackware.com</a>. You can install it using <i>installpkg</i>.</p>
<a name="freebsd"></a>
<span class="heading2">FreeBSD</span><br>
<p>If you have an internet connection, run <i>pkg_add -r mysql</i>.
When the command completes, MySQL will be installed. You can also install
MySQL from the Ports CD(s) that came with your distribution using
<i>/stand/sysinstall</i>.</p>
<a name="openbsd"></a>
<span class="heading2">OpenBSD</span><br>
<p>The mysql-client and mysql-server packages are available from
<a href="ftp://ftp.openbsd.org">ftp.openbsd.org</a> or on CD's that came with
your distribution. You can install them using <i>pkg_add</i>.</p>
<a name="netbsd"></a>
<span class="heading2">NetBSD</span><br>
<p>The mysql-client and mysql-server packages are available from
<a href="ftp://ftp.netbsd.org">ftp.netbsd.org</a> or on CD's that came with
your distribution. You can install them using <i>pkg_add</i>.</p>
<a name="openserver"></a>
<span class="heading2">SCO OpenServer</span><br>
<p>For SCO OpenServer, MySQL packages are available from the
<a href="ftp://ftp2.caldera.com/pub/skunkware/osr5/vols">Skunkware ftp
server</a>. SCO OpenServer
packages are often called VOL's because they come as a set of files named
VOL.000.000, VOL.000.001, etc. These VOLS can be installed using the Software
Manager (custom).</p>
<a name="solaris"></a>
<span class="heading2">Solaris</span><br>
<p>The Solaris Companion CD provides MySQL and it's downloadable in package
form from many web sites including
<a href="http://www.mysql.com/downloads/os-solaris.html">the MySQL site</a>.
You can use <i>pkgtool</i> to install the package. Note, that with some
versions of Solaris and some versions of MySQL, you have to create a "wheel"
group before installing the MySQL package. You can do this (as root) using
the command: <i>/usr/sbin/groupadd wheel</i></p>
<a name="source"></a>
<span class="heading2">Compiling From Source</span><br>
<p>If you want to compile MySQL from source, it should compile cleanly on all
of the platforms mentioned above. The source code is available from
<a href="http://www.mysql.com">the MySQL site</a>. With older versions of
MySQL, I've run out of memory while compiling on machines with less than 64
meg. I don't believe that this is still a problem though. I usually give the
<i>configure</i> script the <i>--prefix=/usr/local/mysql</i> parameter so that
MySQL will be installed entirely under /usr/local/mysql. I then add
/usr/local/mysql/bin to my PATH environment variable and
/usr/local/mysql/lib/mysql to my LD_LIBRARY_PATH environment variable.</p>
<a name="startingatboot"></a>
<span class="heading2">Starting the Database at Boot Time</span><br>
<p>The package distributions of MySQL install a script which starts the
database at boot time. If you compiled from source, you'll need to install a
script like one of the following to start the database at boot time.</p>
<p>If you are using MySQL 4:</p>
<blockquote>
<PRE>
<FONT color=#0000ff>#!/bin/sh</FONT>
<B><FONT color=#a62828>case</FONT></B> "$1" <B><FONT color=#a62828>in</FONT></B>
start<B><FONT color=#a62828>)</FONT></B>
<B><FONT color=#a62828>if</FONT></B> <B><FONT color=#a62828>(</FONT></B> <B><FONT color=#a62828>test</FONT></B> <B><FONT color=#a62828>!</FONT></B> <B><FONT color=#a62828>-d</FONT></B> <B><FONT color=#a62828>"</FONT></B><FONT color=#ff00ff>/usr/local/mysql/var</FONT><B><FONT color=#a62828>"</FONT></B> <B><FONT color=#a62828>)</FONT></B><B><FONT color=#a62828>;</FONT></B> <B><FONT color=#a62828>then</FONT></B>
mkdir <font color="#6b59ce">-p</font> /usr/local/mysql/var/mysql
<B><FONT color=#a62828>fi</FONT></B>
<B><FONT color=#a62828>if</FONT></B> <B><FONT color=#a62828>(</FONT></B> <B><FONT color=#a62828>test</FONT></B> <B><FONT color=#a62828>!</FONT></B> <B><FONT color=#a62828>-d</FONT></B> <B><FONT color=#a62828>"</FONT></B><FONT color=#ff00ff>/usr/local/mysql/var/log</FONT><B><FONT color=#a62828>"</FONT></B> <B><FONT color=#a62828>)</FONT></B><B><FONT color=#a62828>;</FONT></B> <B><FONT color=#a62828>then</FONT></B>
mkdir <font color="#6b59ce">-p</font> /usr/local/mysql/var/log
<B><FONT color=#a62828>fi</FONT></B>
<B><FONT color=#a62828>if</FONT></B> <B><FONT color=#a62828>(</FONT></B> <B><FONT color=#a62828>test</FONT></B> <B><FONT color=#a62828>!</FONT></B> <B><FONT color=#a62828>-d</FONT></B> <B><FONT color=#a62828>"</FONT></B><FONT color=#ff00ff>/usr/local/mysql/var/mysql</FONT><B><FONT color=#a62828>"</FONT></B> <B><FONT color=#a62828>)</FONT></B><B><FONT color=#a62828>;</FONT></B> <B><FONT color=#a62828>then</FONT></B>
/usr/local/mysql/bin/mysql_install_db <font color="#6b59ce">--datadir=/usr/local/mysql/var</font>
<B><FONT color=#a62828>fi</FONT></B>
chown <B><FONT color=#a62828>-R</FONT></B> mysql.mysql /usr/local/mysql/var
<B><FONT color=#a62828>chmod</FONT></B> <FONT color=#ff00ff>0755</FONT> /usr/local/mysql/var
<B><FONT color=#a62828>chmod</FONT></B> <FONT color=#ff00ff>0755</FONT> /usr/local/mysql/var/log
/usr/local/mysql/bin/mysqld_safe <font color="#6b59ce">--datadir=/usr/local/mysql/var</font> <font color="#6b59ce">--err-log=/usr/local/mysql/var/log/mysqld.log</font> <font color="#6b59ce">--log=/usr/local/mysql/var/log/mysqld.log</font> <font color="#6b59ce">--socket=/tmp/mysql.sock</font>
<B><FONT color=#a62828>;;</FONT></B>
stop<B><FONT color=#a62828>)</FONT></B>
<B><FONT color=#a62828>kill</FONT></B> <FONT color=#6959cf>`ps </FONT><FONT color=#6959cf>-efa</FONT><FONT color=#6959cf> </FONT><B><FONT color=#a62828>|</FONT></B><FONT color=#6959cf> </FONT><B><FONT color=#a62828>grep</FONT></B><FONT color=#6959cf> mysql </FONT><B><FONT color=#a62828>|</FONT></B><FONT color=#6959cf> </FONT><B><FONT color=#a62828>grep</FONT></B><FONT color=#6959cf> </FONT><FONT color=#6959cf>-v</FONT><FONT color=#6959cf> </FONT><B><FONT color=#a62828>grep</FONT></B><FONT color=#6959cf> </FONT><B><FONT color=#a62828>|</FONT></B><FONT color=#6959cf> awk </FONT><B><FONT color=#a62828>'</FONT></B><FONT color=#ff00ff>{print $2}</FONT><B><FONT color=#a62828>'</FONT></B><FONT color=#6959cf>`</FONT>
<B><FONT color=#a62828>;;</FONT></B>
*<B><FONT color=#a62828>)</FONT></B>
<B><FONT color=#a62828>echo</FONT></B><FONT color=#ff00ff> $</FONT><B><FONT color=#a62828>"</FONT></B><FONT color=#ff00ff>Usage: </FONT><FONT color=#a620f7>$0</FONT><FONT color=#ff00ff> {start|stop}</FONT><B><FONT color=#a62828>"</FONT></B>
<B><FONT color=#a62828>exit</FONT></B> <FONT color=#ff00ff>1</FONT>
<B><FONT color=#a62828>esac</FONT></B>
<B><FONT color=#a62828>exit</FONT></B> <FONT color=#ff00ff>0</FONT>
</PRE>
</blockquote>
<p>If you are using MySQL 3:</p>
<blockquote>
<PRE>
<FONT color=#0000ff>#!/bin/sh</FONT>
<B><FONT color=#a62828>case</FONT></B> "$1" <B><FONT color=#a62828>in</FONT></B>
start<B><FONT color=#a62828>)</FONT></B>
<B><FONT color=#a62828>if</FONT></B> <B><FONT color=#a62828>(</FONT></B> <B><FONT color=#a62828>test</FONT></B> <B><FONT color=#a62828>!</FONT></B> <B><FONT color=#a62828>-d</FONT></B> <B><FONT color=#a62828>"</FONT></B><FONT color=#ff00ff>/usr/local/mysql/var/mysql</FONT><B><FONT color=#a62828>"</FONT></B> <B><FONT color=#a62828>)</FONT></B><B><FONT color=#a62828>;</FONT></B> <B><FONT color=#a62828>then</FONT></B>
/usr/local/mysql/bin/mysql_install_db
<B><FONT color=#a62828>fi</FONT></B>
chown <B><FONT color=#a62828>-R</FONT></B> mysql.mysql /usr/local/mysql/var
<B><FONT color=#a62828>chmod</FONT></B> <FONT color=#ff00ff>0755</FONT> /usr/local/mysql/var
/usr/local/mysql/bin/safe_mysqld
<B><FONT color=#a62828>;;</FONT></B>
stop<B><FONT color=#a62828>)</FONT></B>
<B><FONT color=#a62828>kill</FONT></B> <FONT color=#6959cf>`ps </FONT><FONT color=#6959cf>-efa</FONT><FONT color=#6959cf> </FONT><B><FONT color=#a62828>|</FONT></B><FONT color=#6959cf> </FONT><B><FONT color=#a62828>grep</FONT></B><FONT color=#6959cf> mysql </FONT><B><FONT color=#a62828>|</FONT></B><FONT color=#6959cf> </FONT><B><FONT color=#a62828>grep</FONT></B><FONT color=#6959cf> </FONT><FONT color=#6959cf>-v</FONT><FONT color=#6959cf> </FONT><B><FONT color=#a62828>grep</FONT></B><FONT color=#6959cf> </FONT><B><FONT color=#a62828>|</FONT></B><FONT color=#6959cf> awk </FONT><B><FONT color=#a62828>'</FONT></B><FONT color=#ff00ff>{print $2}</FONT><B><FONT color=#a62828>'</FONT></B><FONT color=#6959cf>`</FONT>
<B><FONT color=#a62828>;;</FONT></B>
*<B><FONT color=#a62828>)</FONT></B>
<B><FONT color=#a62828>echo</FONT></B><FONT color=#ff00ff> $</FONT><B><FONT color=#a62828>"</FONT></B><FONT color=#ff00ff>Usage: </FONT><FONT color=#a620f7>$0</FONT><FONT color=#ff00ff> {start|stop}</FONT><B><FONT color=#a62828>"</FONT></B>
<B><FONT color=#a62828>exit</FONT></B> <FONT color=#ff00ff>1</FONT>
<B><FONT color=#a62828>esac</FONT></B>
<B><FONT color=#a62828>exit</FONT></B> <FONT color=#ff00ff>0</FONT>
</PRE>
</blockquote>
<p>Install this script and run it with the "start" option to start up the
database. Running it with the "stop" option shuts the database down. To
access a database, it must be running.</p>
<a name="creating"></a>
<span class="heading1">Creating a Database</span><br>
<p>After installation, MySQL is ready to use but to do any useful work, you'll
have to create a database.</p>
<p>The installation process creates a database named <i>mysql</i> containing
privileges and other housekeeping information and a <i>root</i> user which has
no password.</p>
<p>The following commands give the <i>root</i> user the password
<i>newpassword</i>.</p>
<blockquote>
<b>mysql -uroot -e "update user set password=password('newpassword') where user='root'" mysql</b><br>
<b>mysqladmin -uroot reload</b>
</blockquote>
<p>Though you can create tables in the <i>mysql</i> database, it's not a good
idea. You should create a new database. The following command creates a
database called <i>testdb</i>.</p>
<blockquote>
<b>mysqladmin -uroot -pnewpassword create testdb</b>
</blockquote>
<p>To create a user, log into the <i>mysql</i> database using the following
command.</b>
<blockquote>
<b>mysql -uroot -pnewpassword mysql</b>
</blockquote>
<p>The following queries create a user called <i>testuser</i> with password
<i>testpassword</i> and allows it to log in from the local machine or any
remote host.</p>
<blockquote>
<PRE>
<B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> user (host,user,password) <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'localhost'</FONT>,<FONT color=#ff00ff>'testuser'</FONT>,password(<FONT color=#ff00ff>'testpassword'</FONT>));
<B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> user (host,user,password) <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'%'</FONT>,<FONT color=#ff00ff>'testuser'</FONT>,password(<FONT color=#ff00ff>'testpassword'</FONT>));
</PRE>
</blockquote>
<p>Once the user is created, it must be given database-specific priveleges. The
following query gives <i>testuser</i> all privileges on the <i>testdb</i>
database.</p>
<blockquote>
<PRE>
<B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> db <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'%'</FONT>,<FONT color=#ff00ff>'testdb'</FONT>,<FONT color=#ff00ff>'testuser'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>);
</PRE>
</blockquote>
<p>Older versions of MySQL have fewer columns in the <i>db</i> table, if the
query above fails, try this one instead.</p>
<blockquote>
<PRE>
<B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> db <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'%'</FONT>,<FONT color=#ff00ff>'testdb'</FONT>,<FONT color=#ff00ff>'testuser'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>);
</PRE>
</blockquote>
<p>Really old versions of MySQL have fewer columns in the <i>db</i> table, if
the queries fail, try this one instead.</p>
<blockquote>
<PRE>
<B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> db <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'%'</FONT>,<FONT color=#ff00ff>'testdb'</FONT>,<FONT color=#ff00ff>'testuser'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>,<FONT color=#ff00ff>'Y'</FONT>);
</PRE>
</blockquote>
<p>Exit the mysql client and run the following command to activate these
changes.</p>
<blockquote>
<b>mysqladmin -uroot -pnewpassword reload</b>
</blockquote>
<p>To delete a user, log into the <i>mysql</i> database using the following
command.</b>
<blockquote>
<b>mysql -uroot -pnewpassword mysql</b>
</blockquote>
<p>Delete the appropriate rows from the user and db tables. The following
queries remove the <i>testuser</i> user and all database-specific permissions
that <i>testuser</i> had.</p>
<blockquote>
<PRE>
<B><FONT color=#a62828>DELETE</FONT></B> <FONT color=#6959cf>FROM</FONT> <FONT color=#6959cf>user</FONT> <FONT color=#6959cf>WHERE</FONT> <FONT color=#6959cf>user</FONT>=<FONT color=#ff00ff>'testuser'</FONT>;
<B><FONT color=#a62828>DELETE</FONT></B> <FONT color=#6959cf>FROM</FONT> <FONT color=#6959cf>db</FONT> <FONT color=#6959cf>WHERE</FONT> <FONT color=#6959cf>user</FONT>=<FONT color=#ff00ff>'testuser'</FONT>;
</PRE>
</blockquote>
<p>Exit the mysql client and run the following command to activate these
changes.</p>
<blockquote>
<b>mysqladmin -uroot -pnewpassword reload</b>
</blockquote>
<p>If you want to drop the database, you can do so with the following
command.</p>
<blockquote>
<b>mysqladmin -uroot -pnewpassword drop testdb</b>
</blockquote>
<p>This should be enough to get you started. To set up more complex
configurations, consult the MySQL
<a href="http://www.mysql.com/documentation/mysql/bychapter/">online
documentation</a>.</p>
<a name="accessing"></a>
<span class="heading1">Accessing a Database</span><br>
<p>Accessing a MySQL database using the <i>mysql</i> client tool is simple. For
example, to access a database called <i>testdb</i> on the local machine as
the <i>testuser</i> user with password <i>testpassword</i>, use the following
command.</p>
<blockquote>
<b>mysql -utestuser -ptestpassword testdb</b>
</blockquote>
<p>If you want to access a database on a remote machine, say on
<i>testhost</i>, use the -h option as follows.</p>
<blockquote>
<b>mysql -htesthost -utestuser -ptestpassword testdb</b>
</blockquote>
<p>Once you're connected to the database, the <i>mysql</i> client prompts you to
enter a query. Queries may be split across multiple lines. To run a query,
end it with a semicolon or type \g on the next line. To exit, type \q.</p>
<p>A sample <i>mysql</i> session follows.</p>
<blockquote>
<PRE>
[user@localhost user]$ <b>mysql -utestuser -ptestpassword testdb</b>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 3.23.41
Type <FONT color=#ff00ff>'help;'</FONT> or <FONT color=#ff00ff>'\h'</FONT> for help. Type <FONT color=#ff00ff>'\c'</FONT> to clear the buffer.
mysql> <B><FONT color=#a62828>create</FONT></B> <FONT color=#6959cf>table</FONT> testtable (
-> col1 <B><FONT color=#288a51>char</FONT></B>(<FONT color=#ff00ff>40</FONT>),
-> col2 <B><FONT color=#288a51>integer</FONT></B>
-> );
Query OK, <FONT color=#ff00ff>0</FONT> rows affected (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| testtable |
+------------------+
<FONT color=#ff00ff>1</FONT> row in set (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> describe testtable;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| col1 | <B><FONT color=#288a51>char</FONT></B>(<FONT color=#ff00ff>40</FONT>) | YES | | <FONT color=#6959cf>NULL</FONT> | |
| col2 | int(<FONT color=#ff00ff>11</FONT>) | YES | | <FONT color=#6959cf>NULL</FONT> | |
+-------+----------+------+-----+---------+-------+
<FONT color=#ff00ff>2</FONT> rows in set (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> <B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> testtable <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'hello'</FONT>,<FONT color=#ff00ff>50</FONT>);
Query OK, <FONT color=#ff00ff>1</FONT> <FONT color=#6959cf>row</FONT> affected (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> <B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> testtable <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'hi'</FONT>,<FONT color=#ff00ff>60</FONT>);
Query OK, <FONT color=#ff00ff>1</FONT> <FONT color=#6959cf>row</FONT> affected (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> <B><FONT color=#a62828>insert</FONT></B> <FONT color=#6959cf>into</FONT> testtable <FONT color=#6959cf>values</FONT> (<FONT color=#ff00ff>'bye'</FONT>,<FONT color=#ff00ff>70</FONT>);
Query OK, <FONT color=#ff00ff>1</FONT> <FONT color=#6959cf>row</FONT> affected (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> <B><FONT color=#a62828>select</FONT></B> * <FONT color=#6959cf>from</FONT> testtable;
+-------+------+
| col1 | col2 |
+-------+------+
| hello | <FONT color=#ff00ff>50</FONT> |
| hi | <FONT color=#ff00ff>60</FONT> |
| bye | <FONT color=#ff00ff>70</FONT> |
+-------+------+
<FONT color=#ff00ff>3</FONT> rows in set (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> <B><FONT color=#a62828>update</FONT></B> testtable <B><FONT color=#a62828>set</FONT></B> col2=<FONT color=#ff00ff>0</FONT> <FONT color=#6959cf>where</FONT> col1=<FONT color=#ff00ff>'hi'</FONT>;
Query OK, <FONT color=#ff00ff>1</FONT> row affected (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
Rows matched: <FONT color=#ff00ff>1</FONT> Changed: <FONT color=#ff00ff>1</FONT> Warnings: <FONT color=#ff00ff>0</FONT>
mysql> <B><FONT color=#a62828>select</FONT></B> * <FONT color=#6959cf>from</FONT> testtable;
+-------+------+
| col1 | col2 |
+-------+------+
| hello | <FONT color=#ff00ff>50</FONT> |
| hi | <FONT color=#ff00ff>0</FONT> |
| bye | <FONT color=#ff00ff>70</FONT> |
+-------+------+
<FONT color=#ff00ff>3</FONT> rows in set (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> <B><FONT color=#a62828>delete</FONT></B> <FONT color=#6959cf>from</FONT> testtable <FONT color=#6959cf>where</FONT> col2=<FONT color=#ff00ff>50</FONT>;
Query OK, <FONT color=#ff00ff>1</FONT> row affected (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> <B><FONT color=#a62828>select</FONT></B> * <FONT color=#6959cf>from</FONT> testtable;
+------+------+
| col1 | col2 |
+------+------+
| hi | <FONT color=#ff00ff>0</FONT> |
| bye | <FONT color=#ff00ff>70</FONT> |
+------+------+
<FONT color=#ff00ff>2</FONT> rows in set (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> <B><FONT color=#a62828>drop</FONT></B> <FONT color=#6959cf>table</FONT> testtable;
Query OK, <FONT color=#ff00ff>0</FONT> rows affected (<FONT color=#ff00ff>0</FONT>.<FONT color=#ff00ff>00</FONT> sec)
mysql> \q
Bye
</PRE>
</blockquote>
<a name="sqlrelay"></a>
<span class="heading1">Accessing a Database With SQL Relay</span><br>
<p>Accessing MySQL from SQL Relay requires an instance entry in your
<i>sqlrelay.conf</i> file for the database that you want
to access. Here is an example <i>sqlrelay.conf</i> which defines an SQL Relay
instance called mysqltest. This instance connects to the <i>testdb</i>
database on the local machine as the user <i>testuser</i> with password
<i>testpassword</i>.</p>
<PRE>
<FONT color=#0000ff><?</FONT><B><FONT color=#288a51>xml version=</FONT></B><FONT color=#ff00ff>"1.0"</FONT><FONT color=#0000ff>?></FONT>
<FONT color=#008a8e><!</FONT><B><FONT color=#a62828>DOCTYPE</FONT></B> instances <B><FONT color=#a62828>SYSTEM</FONT></B> <FONT color=#ff00ff>"sqlrelay.dtd"</FONT><FONT color=#008a8e>></FONT>
<FONT color=#008a8e><instances></FONT>
<FONT color=#008a8e><instance id=</FONT><FONT color=#ff00ff>"mysqltest"</FONT><FONT color=#008a8e> port=</FONT><FONT color=#ff00ff>"9000"</FONT><FONT color=#008a8e> socket=</FONT><FONT color=#ff00ff>"/tmp/mysqltest.socket"</FONT><FONT color=#008a8e> dbase=</FONT><FONT color=#ff00ff>"mysql"</FONT><FONT color=#008a8e> connections=</FONT><FONT color=#ff00ff>"3"</FONT><FONT color=#008a8e> maxconnections=</FONT><FONT color=#ff00ff>"5"</FONT><FONT color=#008a8e> maxqueuelength=</FONT><FONT color=#ff00ff>"0"</FONT><FONT color=#008a8e> growby=</FONT><FONT color=#ff00ff>"1"</FONT><FONT color=#008a8e> ttl=</FONT><FONT color=#ff00ff>"60"</FONT><FONT color=#008a8e> endofsession=</FONT><FONT color=#ff00ff>"commit"</FONT><FONT color=#008a8e> sessiontimeout=</FONT><FONT color=#ff00ff>"600"</FONT><FONT color=#008a8e> runasuser=</FONT><FONT color=#ff00ff>"nobody"</FONT><FONT color=#008a8e> runasgroup=</FONT><FONT color=#ff00ff>"nobody"</FONT><FONT color=#008a8e> cursors=</FONT><FONT color=#ff00ff>"5"</FONT><FONT color=#008a8e> authtier=</FONT><FONT color=#ff00ff>"listener"</FONT><FONT color=#008a8e> handoff=</FONT><FONT color=#ff00ff>"pass"</FONT><FONT color=#008a8e>></FONT>
<FONT color=#008a8e><users></FONT>
<FONT color=#008a8e><user user=</FONT><FONT color=#ff00ff>"mysqltest"</FONT><FONT color=#008a8e> password=</FONT><FONT color=#ff00ff>"mysqltest"</FONT><FONT color=#008a8e>/></FONT>
<FONT color=#008a8e></users></FONT>
<FONT color=#008a8e><connections></FONT>
<FONT color=#008a8e><connection connectionid=</FONT><FONT color=#ff00ff>"mysqltest"</FONT><FONT color=#008a8e> string=</FONT><FONT color=#ff00ff>"user=testuser;password=testpassword;db=testdb"</FONT><FONT color=#008a8e> metric=</FONT><FONT color=#ff00ff>"1"</FONT><FONT color=#008a8e>/></FONT>
<FONT color=#008a8e></connections></FONT>
<FONT color=#008a8e></instance></FONT>
<FONT color=#008a8e></instances></FONT>
</PRE>
<p>If you want to connect to a database on a remote machine, say on
<i>testhost</i>, you would need to add <i>host=testhost;</i> to the string
attribute of the connection tag.</p>
<p>Now you can start up this instance with the following command.</p>
<blockquote>
<b>sqlr-start -id mysqltest</b>
</blockquote>
<p>To connect to the instance and run queries, use the following command.</p>
<blockquote>
<b>sqlrsh -id mysqltest</b>
</blockquote>
<p>The following command shuts down the SQL Relay instance.</p>
<blockquote>
<b>sqlr-stop mysqltest</b>
</blockquote>
<a name="quirks"></a>
<span class="heading1">MySQL Quirks</span><br>
<p>Most versions of MySQL don't support transactions, but some do. If you're
using MySQL-max or if you built MySQL with Innodb support, then you have the
option of running MySQL with support for transactions.</p>
<p>MySQL does not support foreign key constraints. For example, take the
following table declarations:</p>
<blockquote>
<pre>
<font color="#a02828"><b>create</b></font> <font color="#6858c8">table</font> cars (
car_id int <font color="#a02828"><b>not</b></font> <font color="#6858c8">null</font>,
...
);
<font color="#a02828"><b>create</b></font> <font color="#6858c8">table</font> carkeys (
carkey_id int <font color="#a02828"><b>not</b></font> <font color="#6858c8">null</font>,
...
);
<font color="#a02828"><b>create</b></font> <font color="#6858c8">table</font> keys_of_cars (
car_id int <font color="#a02828"><b>not</b></font> <font color="#6858c8">null</font>,
carkey_id int <font color="#a02828"><b>not</b></font> <font color="#6858c8">null</font>,
...
foreign key (car_id) references cars (car_id),
foreign key (carkey_id) references carkeys (carkey_id)
);
</pre>
</blockquote>
<p>In many other databases, attempting to insert car_id's and carkey_id's into
the keys_of_cars table will fail unless those car_id's and carkey_id's exist in
the cars and carkeys tables respectively. Under MySQL, this will not fail.</p>
<p>What's quirky about MySQL is that it allows the foreign key syntax, but
ignores it. Other databases that don't support foreign keys don't allow the
syntax either.</p>
</body>
</html>
|