今天帮别人恢复了论坛,为了避免以后再次发生这种情况,还是每天备份一下的好,就写了一个批处理加入到计划任务里面每天执行一次就行了。
准备工作:
1.安装winrar,这个应该基本上都装了吧,我是装在c:\program files\winra
2.创建一个databak文件夹,我是在F:\databak下
然后将下面的文件存成一个backup.cmd
net stop mysql
C:\progra~1\WinRAR\winrar a -ag -k -r -s f:\databak\dsbclub.rar d:\mysql\data\db1name\
C:\progra~1\WinRAR\winrar a -ag -k -r -s f:\databak\dsbclub.rar d:\mysql\data\db2name\
……
C:\progra~1\WinRAR\winrar a -ag -k -r -s f:\databak\dsbclub.rar d:\mysql\data\dbnname\
xcopy f:\databak\*.* f:\databak\%date:~0,10%\ /y
del f:\databak\*.* /q
net start mysql
然后用计划任务设置好每天凌晨备份即可,此方法的缺点是需要暂停mysql,所以最好在凌晨的时候执行
centos/linux下面用rpm方法安装mysql5.1
首先还是要下载,因为我是64位的linux,所以下载的是64bit的版本,需要下三个文件server和
64bit mysql 下载地址
MySQL-server-community-5.1.36-0.rhel5.x86_64.rpm
http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-server-community-5.1.36-0.rhel5.x86_64.rpm/from/ftp://mysql.cdpa.nsysu.edu.tw/Unix/Database/MySQL/
MySQL-client-community-5.1.36-0.rhel5.x86_64.rpm
http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-client-community-5.1.36-0.rhel5.x86_64.rpm/from/ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/
MySQL-devel-community-5.1.36-0.rhel5.x86_64.rpm
http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-devel-community-5.1.36-0.rhel5.x86_64.rpm/from/ftp://ftp.mirror.tw/pub/mysql/
32bit和更多下载镜像,请自己上www.mysql.com下载
这里预设下载目录为/usr/local/src/
依次执行以下命令
#下载所需rpm包
cd /usr/local/src/
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-server-community-5.1.36-0.rhel5.x86_64.rpm/from/ftp://mysql.cdpa.nsysu.edu.tw/Unix/Database/MySQL/
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-client-community-5.1.36-0.rhel5.x86_64.rpm/from/ftp://ftp.stu.edu.tw/pub/Unix/Database/Mysql/
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-devel-community-5.1.36-0.rhel5.x86_64.rpm/from/ftp://ftp.mirror.tw/pub/mysql/
#开始安装
rpm -ivh MySQL-server-community-5.1.36-0.rhel5.x86_64.rpm MySQL-client-community-5.1.36-0.rhel5.x86_64.rpm MySQL-devel-community-5.1.36-0.rhel5.x86_64.rpm
然后运行一下mysql看是否安装成功
mysql
提示:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.36-community-log MySQL Community Server (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
即为安装成功
修改登录密码:
mysqladmin -u root password ‘new-password’
格式:mysqladmin -u用户名 -p旧密码 password 新密码
再次登录
mysql -u root -p
mysql -h localhost -u username -p //登录mysql数据库
create database dbname;//创建数据库
insert into 表名 (字段1,字段2,字段3,…) values (数据1,数据2,数据3,…);
select * from 表名 where 条件;
SELECT * FROM `customers` WHERE name like ("%mi%");
select orders.orderid, orders.amount, orders.date from customers, orders where customers.name = ‘Julie Smith’ and customers.customerid = orders.customerid;
delete from 表名 where 条件;
update 表名 set 表达式(如 字段=“值”) where 条件;
php数据库链接
@ $db = new mysqli(‘localhost’, ‘用户名’, ‘密码’, ‘数据库’);
php执行SQL语句
$query = "sql语句";
$result = $db->query($query);
最近评论