- 论坛徽章:
- 0
|
多谢,好像这样就可以了。我把命令都写下来:
mysql> CREATE DATABASE my_1st_db CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
mysql> show DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| my_1st_db |
+--------------------+
mysql> use my_1st_db;
Database changed
mysql> create table my_1st_table (USR varchar(30), INFO varchar(30));
Query OK, 0 rows affected (0.01 sec)
mysql> desc my_1st_table;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| USR | varchar(30) | YES | | NULL | |
| INFO | varchar(30) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
mysql> insert into my_1st_table set USR='光明', INFO='学习中';
Query OK, 1 row affected (0.00 sec)
mysql> select * from my_1st_table;
+--------+-----------+
| USR | INFO |
+--------+-----------+
| 光明 | 学习中 |
+--------+-----------+
然后我写了个小的perl script来试验:
#!/usr/bin/perl
use strict;
use warnings;
use DBI();
use utf8;
my $data_source = 'my_1st_db';
my $username = 'XXXXXXXX';
my $password = 'XXXXXXXX';
# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=$data_source",
"$username", "$password",
{'RaiseError' => 1});
my $sql = "INSERT INTO my_1st_table VALUES('齐秦', '狼')";
$dbh->do($sql);
my $ref = $dbh->selectall_arrayref(
"SELECT USR, INFO FROM my_1st_table",
{ Slice => {} }
);
foreach my $q ( @$ref ) {
print "USER: $q->{USR} => INFO: $q->{INFO}\n";
}
ubuntu>./test_mysql.pl
USER: 光明 => INFO: 学习中
USER: 齐秦 => INFO: 狼 |
|