- 追加された行はこの色です。
- 削除された行はこの色です。
**別ホストのMysqlに接続する [#nd01d9e1]
mysql -h 192.175.242.89 -u root
*** mysqlというDBにrootでログインする。 [#q88fae77]
mysql -u root mysql
mysql -u iiicbg mysql はNGみたい(上のはrootだから?)
*** テーブル定義を参照する [#qc88633b]
テーブルがどの様なSQL文で作成されたか表示します。
mysql> show create table webdb1.rss;
| Table | Create Table
| rss | CREATE TABLE `rss` (
`id` int(10) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`link` text,
`date` datetime default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
参考:~
http://www.rfs.jp/sitebuilder/sql/04/07.html#SHOW%20CREATE%20TABLE
*** MySQL 5.0を使う [#c2f720e3]
Fedora Core release 3 (Heidelberg) にインストールしました。とりあえず、
MySQL-Max-5.0.15-0.i386.rpm
MySQL-server-5.0.15-0.i386.rpm
MySQL-client-5.0.15-0.i386.rpm <- Linux上のクライアント
mysql-administrator-1.1.4-win.msi <- Windowsのクライアントとして
で動いてるっぽいです。
***my.cnfたちのある場所 [#y29b92f7]
rpmでインストールした場合、
/usr/share/mysql/my-medium.cnf
などにあるみたいです。
***ユーザ追加 [#sc565914]
webdb1というデータベースに接続可能なhogeというユーザ(パスワードはfuga)を追加する
mysql> grant all privileges on webdb1.* to hoge identified by 'fuga';
Query OK, 0 rows affected (0.00 sec)
このユーザはリモートからも接続可能です。
*** 他のユーザの権限を見る [#j5acda4a]
>mysql -u root mysql
mysql> use mysql;
Database changed
mysql> select * from user;
+-------------+------+----------+-------------+-------------+--------------+------------+ 〜
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Grant_priv | 〜
+-------------+------+----------+-------------+-------------+--------------+------------+ 〜
| localhost | root | | Y | Y | Y | Y | 〜
| ctkyos18121 | root | | Y | Y | Y | Y | 〜
| localhost | | | N | N | N | N | 〜
| ctkyos18121 | | | N | N | N | N | 〜
+-------------+------+----------+-------------+-------------+--------------+------------+ 〜
4 rows in set (0.01 sec)
mysql>
***リモートで接続可能にする [#s9aab8b3]
デフォルトでは、MySQLは外部からの接続を許可していません。あるユーザ(xxx)が外部から接続可能にする為には以下のようにします。
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.15-max
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> Use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SELECT Host, User, Select_priv, Insert_priv,Update_priv, Delete_priv FROM user;
+--------------+------+-------------+-------------+-------------+-------------+
| Host | User | Select_priv | Insert_priv | Update_priv | Delete_priv |
+--------------+------+-------------+-------------+-------------+-------------+
| localhost | root | Y | Y | Y | Y |
| localhost | | N | N | N | N |
+--------------+------+-------------+-------------+-------------+-------------+
4 rows in set (0.00 sec)
mysql> grant all on *.* to xxx identified by 'hogehoge';
Query OK, 0 rows affected (0.02 sec)
mysql> set password for xxx = password('hogehoge');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
***環境設定を参照する [#c927aa3b]
mysqladmin variable
***文字コードを指定して、接続する [#n816fda4]
mysql -u xxxx -h xxx.xxx.xxx.xxx -p --default-character-set=ujis
など
***ユーザ情報の削除。ユーザの追加 [#ca51c9e9]
DB Magazine 2004/12を読んだのですが、あらかじめ設定されているユーザ情報があると混乱するので、まずは消してからrootなどを新規作成した方がすっきりするとのこと。こんな感じでやってみました。
# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19 to server version: 5.0.15-standard
mysql> truncate table mysql.user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from mysql.user;
Empty set (0.00 sec)
mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'hogehoge' with grant option;
Query OK, 0 rows affected (0.00 sec)
grantする前にログアウトしちゃうと、入れなくなっちゃうので注意!
***関連リンク [#nd56bba6]
-[[Error - "Host not allowed to connect to server" / / MySQL Data Base 接続方法:http://www.sqlgate.com/jp/support/connectmysql.html]]
----
SIZE(10){現在のアクセス:&counter;}