apt-getで取得。データーベースのインストールです。ソースからインストールでも良いですが大変なのでrpmで実施。
apt-get update apt-get install MySQL MySQL-client MySQL-devel MySQL-shared MySQL-Max apt-get clean
/usr/bin/mysql_install_dbこれで/var/lib/msql以下に作成される。
chown -R mysql.mysql /var/lib/mysql
mysqladmin versionでたくさんバージョン関連の文字が表示される。
netstat -atこの表示がされれば起動済み。
tcp 0 0 *:mysql *:* LISTEN
mysqld のshutdownは
mysqladmin shutdown
再起動は
safe_mysqld &
mysqladmin -u root password 'xxxxxxx'(xxxxxxxx は適切なMySQLのパスワード)
rpmからインストールしているので登録済みなので必要無し。
上のMysqlAdminでパスワードの設定していない場合は以下の方法でもOKです。
※MySQLのインストールを行うと、デフォルトでrootというDB用のスーパーユーザを作成しますが、このユーザは、MySQLに関する全権限を保持しているにも関わらず、パスワードが設定されていません。rootにパスワードの設定を行います。
※suコマンドにてmysqlユーザに変更してから以下を実施。
mysql -u root (省略) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> #入力待ちになったらパスワードを設定するコマンドを入力。 mysql> set password for root=password('パスワードを入力'); Query OK, 0 rows affected (0.04 sec) #設定を反映 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) #終了 mysql> exit
パスワードが設定されたか確認
mysql -u root -p Enter password: ← 設定したパスワードを入力 #パスワード入力後ログインできれば成功 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 to server version: 4.0.14 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
※MySQLのインストールを行うと、デフォルトで匿名ユーザーを作成します。しかし、このユーザは、セキュリティ面を考慮すると不要ですので、下記手順にて削除します。
※suコマンドにてmysqlユーザに変更していることが前提。
mysql -u root -p mysql Enter password: ← 設定したパスワードを入力 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 to server version: 4.0.14 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. #入力待ちになったら匿名ユーザーを削除するコマンドを入力。 mysql> delete from user where user=''; Query OK, 2 rows affected (0.05 sec) #設定を反映 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) #終了 mysql> exit
mysql> create database testdb; ← DB(testdb)の作成
mysql -u root -p testdb
mysql> use testdb; ← テーブルの作成先DB(testdb)の指定 ※異なるDBに接続している場合に必要 mysql> create table testtbl( -> test_cd char(5) not null primary key, -> test_text char(10) -> );
mysql -u root -p testdb < create.sql