1. MySQL Setup

Last Updated: Graph.K

1.1 Apache

<Location /mysql>
        DefaultLanguage ja
        AddDefaultCharset euc-jp

1.2 Wakeup

root@www mysql]# mysqladmin ping
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user: 'root@localhost' (Using password: NO)'
[root@www mysql]# mysqladmin -p ping
Enter password: *****
mysqld is alive
[root@www mysql]# /etc/init.d/mysqld stop
MySQLを停止中:                                             [  OK  ]
[root@www mysql]# /etc/init.d/mysqld start
MySQLを起動中:                                             [  OK  ]
[root@www mysql]#

1.3 User Account

mysqladmin -p -u <username> password <password>

1.4 Create DB

mysqladmin -p -u <username> create <DB name>

[root@www mysql]# mysqladmin -u root -p create test3
Enter password: *******

Where command is a one or more of: (Commands may be shortened)
  create databasename   Create a new database
  drop databasename     Delete a database and all its tables
  extended-status       Gives an extended status message from the server
  flush-hosts           Flush all cached hosts
  flush-logs            Flush all logs
  flush-status          Clear status variables
  flush-tables          Flush all tables
  flush-threads         Flush the thread cache
  flush-privileges      Reload grant tables (same as reload)
  kill id,id,...        Kill mysql threads
  password new-password Change old password to new-password
  ping                  Check if mysqld is alive
  processlist           Show list of active threads in server
  reload                Reload grant tables
  refresh               Flush all tables and close and open logfiles
  shutdown              Take server down
  status                Gives a short status message from the server
  start-slave           Start slave
  stop-slave            Stop slave
  variables             Prints variables available
  version               Get version info from server

1.5 Create Table and Records(SQL: create table)

-- create.txt --
create table test1 (number int(10) unique not null,name char(40) not null,note char(60));
insert into test1 values(1,'abc','test1');
insert into test1 values(2,'def','test2');
insert into test1 values(3,'ghi',"test3");
insert into test1 values(4,'imyme',"youyouryou");
insert into test1 values(5,'あいうえお',"日本語漢字");
insert into test1 values(6,'かきくけこ',"日本の大学");
-- end ---

mysql -p test < create.txt

1.6 mysql command

help    (\h)    Display this help.
?       (\?)    Synonym for `help'.
clear   (\c)    Clear command.
connect (\r)    Reconnect to the server. Optional arguments are db and host.
edit    (\e)    Edit command with $EDITOR.
ego     (\G)    Send command to mysql server, display result vertically.
exit    (\q)    Exit mysql. Same as quit.
go      (\g)    Send command to mysql server.
nopager (\n)    Disable pager, print to stdout.
notee   (\t)    Don't write into outfile.
pager   (\P)    Set PAGER [to_pager]. Print the query results via PAGER.
print   (\p)    Print current command.
quit    (\q)    Quit mysql.
rehash  (\#)    Rebuild completion hash.
source  (\.)    Execute a SQL script file. Takes a file name as an argument.
status  (\s)    Get status information from the server.
tee     (\T)    Set outfile [to_outfile]. Append everything into given outfile.
use     (\u)    Use another database. Takes database name as argument.