PythonでWebアプリを作ってみようと試みている(現在進行形)。
自分用備忘録として、コマンドログを記載。
手始めに、不慣れなMySQLの操作。
$ mysql -u root -p Enter password:[何も入力せずEnter] Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 to server version: 5.0.27-standard-log Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer. mysql> set password for root@localhost=password(‘[パスワード]’); Query OK, 0 rows affected (0.00 sec) mysql> create user [一般ユーザ名] identified by ‘[パスワード]’; Query OK, 0 rows affected (0.00 sec) mysql> create database [データベース名]; Query OK, 1 row affected (0.02 sec) mysql> grant all on [データベース名].* to [一般ユーザ名]@localhost; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> \q Bye
プロジェクトの作成。
$ django-admin.py startproject [プロジェクト名]
テストサーバの起動。
$ python manage.py runserver 0.0.0.0:8000
(0.0.0.0を指定すると別PCからアクセスできる)
アプリケーションの作成。
$ python manage.py startapp [アプリケーション名]
モデルとデータベースの同期。
$ python manage.py syncdb
→MySQLdbモジュールが無いって言われたorz
# apt-cache search python | grep mysql
→該当なしorz
MySQLdbをビルドしてみる。
# apt-get install python-setuptools MySQL-devel zlib-devel # tar xzvf MySQL-python-1.2.3c1.tar.gz # cd MySQL-python-1.2.3c1 # python setup.py build # python setup.py install
リトライ。
$ python manage.py syncdb
→なんかDBへのアクセスが拒否されました的なメッセージorz
MySQLのユーザパスワードを再設定してみる。
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 to server version: 5.0.27-standard-log Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer. mysql> set password for [ユーザ名]@localhost = password(‘[パスワード]’); Query OK, 0 rows affected (0.00 sec) mysql> \q Bye
リトライ2nd。
$ python manage.py syncdb Creating table ...
うまく行ったっぽい。
とりあえず管理画面を出すとこまで来た。
コメント