perl&mysql

相关库

1
2
3
perl -MCPAN -e shell
install DBI
install DBD::mysql

然后

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use strict;
use DBI;
my $host = "localhost"; # 主机地址
my $driver = "mysql"; # 接口类型 默认为 localhost
my $database = "perldb"; # 数据库
# 驱动程序对象的句柄
my $dsn = "DBI:$driver:database=$database:$host";
my $userid = "root"; # 数据库用户名
my $password = "123"; # 数据库密码
# 连接数据库
my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
my $sth = $dbh->prepare("SELECT * FROM user"); # 预处理 SQL 语句
$sth->execute(); # 执行 SQL 操作
while ( my @row = $sth->fetchrow_array() )
{
print join(' ', @row)."\n";
}
$sth->finish();
$dbh->disconnect();
1
2
[email protected]:~/Desktop/perlHomework/perlHomework$ ./db.pl
jascal 123

Ubuntu16.04下MySQL的配置

1.从官网下载 MySQL APT Repository
sudo dpkg -i mysql-apt-config_0.7.3-1_all.deb

2.更新源
sudo apt-get update

3.安装MySQL服务器
sudo apt-get install mysql-server

4.查看MySQL服务是否启动
netstat -tap | grep mysql

5.查看MySQL相关位置
whereis mysql
(/etc/mysql目录下存放mysql的配置文件my.cnf。用户可根据需要配置。)

6.修改MySQL-Server字符集
找到配置文件/etc/mysql/my.cnf,或其相关文件

在[mysqld]下添加
character-set-server=utf8

重启MySQL服务
service mysql restart

7.登陆MySQL
mysql -u root -p

8.修改MySQL-Client字符集
mysql> charset utf8

9.查看状态
mysql> status

转自http://blog.csdn.net/ann_rps/article/details/52043923