mysql-server mysql-client mysql-doc
# /usr/bin/mysqladmin -u root password 'new-password'
#vi /root/.my.cnf 参考:/usr/share/doc/mysql-doc,www.mysql.com(MySQLマニュアル)
注意:このファイルは"password"行を含むときはいつでも"user"行を含みます。 Debianメンテナンススクリプトは/etc/mysql/debian.cnfを使い、 ユーザ名"debian-sys-maint"を使います。 しかしパスワードはルートの .my.cnfにあります。 /root/.my.cnfに対する変更はmysqlのcronスクリプトにも影響があることにも注意し てください。
$ mysqladmin -u root password hogehogehog
$ mysql -u root -p Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 to server version: 3.23.49-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> quit Bye
DB作成Sledgeで使用するデータベース www1とユーザ wwwdataを作成します。 wwwdataにはwww1というデータベースにのみアクセス権限を与えます。 $ mysql -u root mysql -p Enter password: ******** Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 to server version: 3.23.49-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database www1; Query OK, 1 row affected (0.00 sec) mysql> grant usage on *.* to wwwdata@localhost identified by '3edc4rfv'; Query OK, 0 rows affected (0.00 sec) mysql> grant all on www1.* to wwwdata@localhost; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye
最初に「grant usage on *.* …」としてグローバルな権限を無しに設定します。 次に「grant all on www1.* …」としてデータベースwww1に限って全ての 権限を与えます。
$ mysql -u wwwdata -p www1 Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 to server version: 3.23.49-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create table dummy (name varchar(20), memo varchar(255)); Query OK, 0 rows affected (0.00 sec) mysql> show tables; +----------------+ | Tables_in_www1 | +----------------+ | dummy | +----------------+ 1 row in set (0.00 sec) mysql> drop table dummy; Query OK, 0 rows affected (0.00 sec) mysql> show tables; Empty set (0.00 sec) mysql> quit Bye
mysqlユーティリティはMySQLへのコマンドライン・インターフェースです。起動する ためには、Linuxのシェル上で以下のコマンドを入力してください。
shell>mysql -u root -pxxxxx
上はユーザがrootでそのパスワードがxxxxxであることを意味します。このコマンド の結果、次のようなmysqlのコマンドラインに入ります。
mysql>
mysql>CREATE DATABASE test1; mysql>GRANT ALL ON bbsdb.* TO test1@localhost identified by "wwwdata";
このGRANTコマンドは、データベースbbsdbの全てのテーブルに対して、全権利(ALL) を持つユーザwwwdataをパスワード3edc4rfvで作成します。
mysql>FLUSH PRIVILEGES;
FLUSHコマンドを実行した時点でtest1のwwwdataへのアクセスが有効になります。これ 以降データベースtest1へのアクセスはユーザwwwdataで行います。
コマンド \q でmysqlを終わり、シェルへ戻ります。 mysql>\q SHELL>
・データベースの表示(show databases;) ここではデータベースの削除の前後に2度表示しています。
・データベースの削除(drop database bbsdb;) ここではデータベースbbsdbを削除しています。
・テーブルの表示(show tables;) ここではテーブル削除の前後に2度表示しています。
・テーブルの削除(drop table bbs_table;) ここではテーブルbbs_tableを削除しています。
mysql> create table テーブル名 (フィールド名1 データ型1, フィールド名2 カラム名2 データ型2, ...);
mysql> update テーブル名 set フィールド名1 = 値1 , フィールド名2 = 値2, ... where 条件;
delete from テーブル名 where 条件式;
mysql> select 検索したいフィールド名 from 検索対象であるテーブル名;
select * from fruit where name = 'apple';