重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
点击电脑‘运行’,输入cmd,然后点击确定。
专注于为中小企业提供成都做网站、网站制作服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业登封免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
cmd
2.找到sql的安装路径,打开命令行,进入Binn目录,输入:cmd,回车执行。
binn大致就在这个里面D:\Program Files\Microsoft SQL Server\100\Tools\Binn
3.执行下列语句:
sqlcmd -S localhost -U sa -P pwzyy!@#123 -i C:\Users\Administrator\Desktop\script.sql
说明:
-S:数据库服务器地址,我这里是本机直接用localhost
-U:用户名
-P:密码
-d:数据库名
-i:sql文件
0. 目标端必须有同名表,没有则建一个空表;
####################################
1、 源端文件准备
源端:
flush tables t for export;
复制
t.ibd, t.cfg到目标端。
###############################
flush tables tt7 for export;
cp tt7* ../ops
2、 目标端存在同样的表则丢弃原来的数据文件
目标端:
alter table tt7 discard tablespace;
3、 目标端加载新的数据文件 t.ibd
alter table tt7 import tablespace;
4、源端释放锁
源端:
unlock tables;
过程中主要异常处理:
#####################################################
SELECT * FROM ops2.tt7 ;
SELECT * FROM ops.tt7 ;
import tablespace报错:
mysql alter table tt7 import tablespace;
ERROR 1812 (HY000): Tablespace is missing for table ops.tt7.
确认再相应的目录存在两个文件
确认属主和权限
#####################################################
过程
[root@qaserver120 ops]# ll
total 80
drwxr-xr-x 2 root root 36 Dec 2 21:42 000
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt2.ibd
[root@qaserver120 ops]#
[root@qaserver120 ops]#
[root@qaserver120 ops]#
[root@qaserver120 ops]# cp 000
[root@qaserver120 ops]# ll
drwxr-xr-x 2 root root 36 Dec 2 21:42 000
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt2.ibd
-rw-r----- 1 root root 627 Dec 2 21:45 tt7.cfg
-rw-r----- 1 root root 114688 Dec 2 21:45 tt7.ibd
[root@qaserver120 ops]# chown mysql.mysql tt7*
[root@qaserver120 ops]#
[root@qaserver120 ops]# ll
drwxr-xr-x 2 root root 36 Dec 2 21:42 000
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt2.ibd
-rw-r----- 1 mysql mysql 627 Dec 2 21:45 tt7.cfg
-rw-r----- 1 mysql mysql 114688 Dec 2 21:46 tt7.ibd
[root@qaserver120 ops]#
#####################################################
mysql show tables;
+---------------+
| Tables_in_ops |
+---------------+
| tt2 |
| tt7 |
+---------------+
2 rows in set (0.00 sec)
mysql select * from tt7;
ERROR 1814 (HY000): Tablespace has been discarded for table 'tt7'
mysql alter table tt7 import tablespace;
ERROR 1812 (HY000): Tablespace is missing for table ops.tt7.
mysql
mysql alter table tt7 import tablespace;
Query OK, 0 rows affected (0.08 sec)
mysql
mysql select * from tt7;
+--------------+------+
| x | y |
+--------------+------+
| BBBBBB | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
mysql
###############################################
################################################
mysql mysql show tables;
+----------------+
| Tables_in_ops2 |
+----------------+
| tt2 |
| tt3 |
| tt7 |
+----------------+
3 rows in set (0.00 sec)
mysql
mysql use ops
Database changed
mysql show tables;
+---------------+
| Tables_in_ops |
+---------------+
| tt2 |
+---------------+
1 row in set (0.00 sec)
mysql
mysql use ops2;
Database changed
mysql select * from tt7;
+--------+------+
| x | y |
+--------+------+
| BBBBBB | NULL |
+--------+------+
1 row in set (0.00 sec)
mysql
mysql
mysql insert into tt7 select * from tt3;
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql insert into tt7 select * from tt3;
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql select * from tt7;
+--------------+------+
| x | y |
+--------------+------+
| BBBBBB | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
mysql
mysql commit;
Query OK, 0 rows affected (0.00 sec)
mysql
mysql exit
Bye
[root@qaserver120 pkg]# cd /data/mysql/ops2
[root@qaserver120 ops2]# ll
total 240
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt2.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt3.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:36 tt7.ibd
[root@qaserver120 ops2]#
[root@qaserver120 ops2]#
[root@qaserver120 ops2]#
[root@qaserver120 ops2]# mysql -u'root' -p'fgxkB9;Zq40^MFQUi$PJ' -A
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 8.0.18 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql use ops2
Database changed
mysql
mysql flush tables tt7 for export;
Query OK, 0 rows affected (0.00 sec)
mysql show tables;
+----------------+
| Tables_in_ops2 |
+----------------+
| tt2 |
| tt3 |
| tt7 |
+----------------+
3 rows in set (0.01 sec)
mysql exit
Bye
[root@qaserver120 ops2]# ll
total 240
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt2.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt3.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:36 tt7.ibd
[root@qaserver120 ops2]# ll
total 240
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt2.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt3.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:36 tt7.ibd
[root@qaserver120 ops2]# pwd
/data/mysql/ops2
[root@qaserver120 ops2]# cd cd /data/mysql
-bash: cd: cd: No such file or directory
[root@qaserver120 ops2]# cd /data/mysql/ops2
[root@qaserver120 ops2]# ll
total 240
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt2.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt3.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:36 tt7.ibd
[root@qaserver120 ops2]# ll -al
total 244
drwxr-x--- 2 mysql mysql 51 Dec 2 21:38 .
drwxr-xr-x 12 mysql mysql 4096 Dec 2 21:17 ..
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt2.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:17 tt3.ibd
-rw-r----- 1 mysql mysql 114688 Dec 2 21:36 tt7.ibd
[root@qaserver120 ops2]# pwd
/data/mysql/ops2
[root@qaserver120 ops2]# mysql -u'root' -p'fgxkB9;Zq40^MFQUi$PJ' -A
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 57
Server version: 8.0.18 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql use ops2
Database changed
mysql show tables;
+----------------+
| Tables_in_ops2 |
+----------------+
| tt2 |
| tt3 |
| tt7 |
+----------------+
3 rows in set (0.00 sec)
mysql select * from tt7;
+--------------+------+
| x | y |
+--------------+------+
| BBBBBB | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
mysql flush tables tt7 for export;
Query OK, 0 rows affected (0.00 sec)
mysql use ops
Database changed
mysql ll
- ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'll' at line 1
mysql show tables;
+---------------+
| Tables_in_ops |
+---------------+
| tt2 |
+---------------+
1 row in set (0.00 sec)
mysql
mysql
mysql alter table tt7 import tablespace;
ERROR 1100 (HY000): Table 'tt7' was not locked with LOCK TABLES
mysql
mysql
mysql use ops2
Database changed
mysql show tables;
+----------------+
| Tables_in_ops2 |
+----------------+
| tt2 |
| tt3 |
| tt7 |
+----------------+
3 rows in set (0.00 sec)
mysql select * from tt7;
+--------------+------+
| x | y |
+--------------+------+
| BBBBBB | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
mysql unlock tables;
Query OK, 0 rows affected (0.00 sec)
mysql show create table tt7;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tt7 | CREATE TABLE `tt7` (
`x` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs DEFAULT NULL,
`y` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_as_cs |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql use ops
Database changed
mysql show tables;
+---------------+
| Tables_in_ops |
+---------------+
| tt2 |
+---------------+
1 row in set (0.01 sec)
mysql CREATE TABLE `tt7` (
- `x` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs DEFAULT NULL,
- `y` int(11) DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_as_cs ;
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql
mysql
mysql show tables;
+---------------+
| Tables_in_ops |
+---------------+
| tt2 |
| tt7 |
+---------------+
2 rows in set (0.00 sec)
mysql select * from tt7;
Empty set (0.00 sec)
mysql
mysql alter table tt7 discard tablesapce;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'tablesapce' at line 1
mysql alter table tt7 discard tablespace;
Query OK, 0 rows affected (0.03 sec)
mysql
mysql
mysql show tables;
+---------------+
| Tables_in_ops |
+---------------+
| tt2 |
| tt7 |
+---------------+
2 rows in set (0.00 sec)
mysql select * from tt7;
ERROR 1814 (HY000): Tablespace has been discarded for table 'tt7'
mysql
mysql
mysql
mysql show tables;
+---------------+
| Tables_in_ops |
+---------------+
| tt2 |
| tt7 |
+---------------+
2 rows in set (0.00 sec)
mysql select * from tt7;
ERROR 1814 (HY000): Tablespace has been discarded for table 'tt7'
mysql
mysql
mysql alter table tt7 import tablespace;
ERROR 1812 (HY000): Tablespace is missing for table `ops`.`tt7`.
mysql
mysql
mysql
mysql alter table tt7 import tablespace;
Query OK, 0 rows affected (0.08 sec)
mysql
mysql
mysql select * from tt7;
+--------------+------+
| x | y |
+--------------+------+
| BBBBBB | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
mysql SELECT * FROM ops2.tt7 ;
+--------------+------+
| x | y |
+--------------+------+
| BBBBBB | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
mysql SELECT * FROM ops.tt7 ;
+--------------+------+
| x | y |
+--------------+------+
| BBBBBB | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
mysql
mysql
mysql
mysql unlock tables;
Query OK, 0 rows affected (0.00 sec)
mysql unlock tables;
Query OK, 0 rows affected (0.00 sec)
mysql use ops
Database changed
mysql show tables;
+---------------+
| Tables_in_ops |
+---------------+
| tt2 |
| tt7 |
+---------------+
2 rows in set (0.00 sec)
mysql
mysql
mysql
mysql use ops2;
Database changed
mysql
mysql
mysql show tables;
+----------------+
| Tables_in_ops2 |
+----------------+
| tt2 |
| tt3 |
| tt7 |
+----------------+
3 rows in set (0.01 sec)
mysql
mysql select * from tt7;
+--------------+------+
| x | y |
+--------------+------+
| BBBBBB | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
mysql
mysql use ops;
Database changed
mysql
mysql
mysql select * from tt7;
+--------------+------+
| x | y |
+--------------+------+
| BBBBBB | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
| AAAAAA | NULL |
| BBBBBB | NULL |
| 555555555555 | NULL |
+--------------+------+
7 rows in set (0.00 sec)
你应该做下数据库的优化了
数据库优化也不是一两句就能说完的
如果是你个程序员,应该加强数据库这方面知识的提高
建议你看本书O'Reilly - High Performance MySQL.chm
网上有中文版的了
你看完会对你有很大的帮助,完全理解了,你就成数据库高手了
一个PHPER的意见
我有个大的 SQL 文件要回放,需要马上做,但又怕压死业务,怎么办?
先来建一个测试库:
塞一些数据进去:
看看我们填充数据的成果:
使用 mysqldump 导出一份数据:
现在我们假设要把这个 dump 文件,回放到一个数据库中,并且现在数据库正在承担很重的业务,我们不希望业务受到太大影响。
先来看看如果直接回放 dump 文件,会发生什么?
我们看到 MySQL 的 cpu 会彪起来,
我们换一个方式来回放 dump:
看看 CPU 压力:
可以看到 CPU 已经非常冷静,并且缓慢的处理数据。
????小贴士:pv 工具既可以用于显示文件流的进度,也可以用于文件流的限速。在本实验中,我们用 PV 来限制 SQL 文件发到 MySQL client 的速度,从而限制 SQL 的回放速度,达到不影响其他业务的效果。
服务器内存占用过高的解决方法:
1,首先通过任务管理器进行进程排序,查找占用内存较大的程序进程。一般占用内存较大的进程有W3WP、sqlserver、mysqld-nt.exe;
2, 站点进程w3wp 可以在cmd命令行中通过 iisapp 命令来对应是那个网站占用内存较大。可以通过设置回收时间、内存最大使用值或共用进程池来减少内存的占用,但是如果要保证网站的访问质量,还是建议升级至更高型号来解决;
3,数据库 sql server 也可以通过数据库的企业管理器来设置最大内存占用,但是如果网站程序必须要占用较大内存的话,设置后会发生页面报错、打不开等问题;
4,MYSQL本身会占用较大虚拟内存,如果不使用mysql数据库的话,可以将其停止。