mysql数据导入到数据库
虽然MySQL安装包中不像SQL Server和Oracle那样提供示例数据库,但官方也提供示例数据库以供学习使用。
官方示例数据库
下载地址
http://dev.mysql.com/doc/index-other.html
Documenation - Other Docs - Example Databases 示例库和文档放到了一起,在employee data 下选择 Download 跳转到下载界面。
导入employees数据库
上传文件到任意路径下
- [[email protected] home1]# ls
- employees_db-full-1.0.6.tar.bz2 mysql mysql-5.6.21.tar.gz
- [[email protected] home1]# tar -xjf employees_db-full-1.0.6.tar.bz2
解压后,可以看见有如下文件
- [[email protected] employees_db]# ll
- total 164680
- -rw-r--r--. 1 501 games 752 Mar 30 2009 Changelog
- -rw-r--r--. 1 501 games 6460 Oct 9 2008 employees_partitioned2.sql
- -rw-r--r--. 1 501 games 7624 Feb 6 2009 employees_partitioned3.sql
- -rw-r--r--. 1 501 games 5660 Feb 6 2009 employees_partitioned.sql
- -rw-r--r--. 1 501 games 3861 Nov 28 2008 employees.sql
- -rw-r--r--. 1 501 games 241 Jul 30 2008 load_departments.dump
- -rw-r--r--. 1 501 games 13828291 Mar 30 2009 load_dept_emp.dump
- -rw-r--r--. 1 501 games 1043 Jul 30 2008 load_dept_manager.dump
- -rw-r--r--. 1 501 games 17422825 Jul 30 2008 load_employees.dump
- -rw-r--r--. 1 501 games 115848997 Jul 30 2008 load_salaries.dump
- -rw-r--r--. 1 501 games 21265449 Jul 30 2008 load_titles.dump
- -rw-r--r--. 1 501 games 3889 Mar 30 2009 objects.sql
- -rw-r--r--. 1 501 games 2211 Jul 30 2008 README
- -rw-r--r--. 1 501 games 4455 Mar 30 2009 test_employees_md5.sql
- -rw-r--r--. 1 501 games 4450 Mar 30 2009 test_employees_sha.sql
导入文件employees.sql (需要制定用户名和密码,不然会报错+_+)
- [[email protected] employees_db]# mysql -t < employees.sql
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- [[email protected] employees_db]# mysql -t < employees.sql -uroot -proot123
- Warning: Using a password on the command line interface can be insecure.
- +-----------------------------+
- | INFO |
- +-----------------------------+
- | CREATING DATABASE STRUCTURE |
- +-----------------------------+
- +------------------------+
- | INFO |
- +------------------------+
- | storage engine: InnoDB |
- +------------------------+
- +---------------------+
- | INFO |
- +---------------------+
- | LOADING departments |
- +---------------------+
- +-------------------+
- | INFO |
- +-------------------+
- | LOADING employees |
- +-------------------+
- +------------------+
- | INFO |
- +------------------+
- | LOADING dept_emp |
- +------------------+
- +----------------------+
- | INFO |
- +----------------------+
- | LOADING dept_manager |
- +----------------------+
- +----------------+
- | INFO |
- +----------------+
- | LOADING titles |
- +----------------+
- +------------------+
- | INFO |
- +------------------+
- | LOADING salaries |
- +------------------+
使用test_employees_sha.sql文件校验数据
- [[email protected] employees_db]# mysql -t < test_employees_sha.sql -uroot -proot123
- Warning: Using a password on the command line interface can be insecure.
- +----------------------+
- | INFO |
- +----------------------+
- | TESTING INSTALLATION |
- +----------------------+
- +--------------+------------------+------------------------------------------+
- | table_name | expected_records | expected_crc |
- +--------------+------------------+------------------------------------------+
- | employees | 300024 | 4d4aa689914d8fd41db7e45c2168e7dcb9697359 |
- | departments | 9 | 4b315afa0e35ca6649df897b958345bcb3d2b764 |
- | dept_manager | 24 | 9687a7d6f93ca8847388a42a6d8d93982a841c6c |
- | dept_emp | 331603 | d95ab9fe07df0865f592574b3b33b9c741d9fd1b |
- | titles | 443308 | d12d5f746b88f07e69b9e36675b6067abb01b60e |
- | salaries | 2844047 | b5a1785c27d75e33a4173aaa22ccf41ebd7d4a9f |
- +--------------+------------------+------------------------------------------+
- +--------------+------------------+------------------------------------------+
- | table_name | found_records | found_crc |
- +--------------+------------------+------------------------------------------+
- | employees | 300024 | 4d4aa689914d8fd41db7e45c2168e7dcb9697359 |
- | departments | 9 | 4b315afa0e35ca6649df897b958345bcb3d2b764 |
- | dept_manager | 24 | 9687a7d6f93ca8847388a42a6d8d93982a841c6c |
- | dept_emp | 331603 | d95ab9fe07df0865f592574b3b33b9c741d9fd1b |
- | titles | 443308 | d12d5f746b88f07e69b9e36675b6067abb01b60e |
- | salaries | 2844047 | b5a1785c27d75e33a4173aaa22ccf41ebd7d4a9f |
- +--------------+------------------+------------------------------------------+
- +--------------+---------------+-----------+
- | table_name | records_match | crc_match |
- +--------------+---------------+-----------+
- | employees | OK | ok |
- | departments | OK | ok |
- | dept_manager | OK | ok |
- | dept_emp | OK | ok |
- | titles | OK | ok |
- | salaries | OK | ok |
- +--------------+---------------+-----------+
使用test_employees_md5.sql文件校验数据
- [[email protected] employees_db]# mysql -t < test_employees_md5.sql -uroot -proot123
- Warning: Using a password on the command line interface can be insecure.
- +----------------------+
- | INFO |
- +----------------------+
- | TESTING INSTALLATION |
- +----------------------+
- +--------------+------------------+----------------------------------+
- | table_name | expected_records | expected_crc |
- +--------------+------------------+----------------------------------+
- | employees | 300024 | 4ec56ab5ba37218d187cf6ab09ce1aa1 |
- | departments | 9 | d1af5e170d2d1591d776d5638d71fc5f |
- | dept_manager | 24 | 8720e2f0853ac9096b689c14664f847e |
- | dept_emp | 331603 | ccf6fe516f990bdaa49713fc478701b7 |
- | titles | 443308 | bfa016c472df68e70a03facafa1bc0a8 |
- | salaries | 2844047 | fd220654e95aea1b169624ffe3fca934 |
- +--------------+------------------+----------------------------------+
- +--------------+------------------+----------------------------------+
- | table_name | found_records | found_crc |
- +--------------+------------------+----------------------------------+
- | employees | 300024 | 4ec56ab5ba37218d187cf6ab09ce1aa1 |
- | departments | 9 | d1af5e170d2d1591d776d5638d71fc5f |
- | dept_manager | 24 | 8720e2f0853ac9096b689c14664f847e |
- | dept_emp | 331603 | ccf6fe516f990bdaa49713fc478701b7 |
- | titles | 443308 | bfa016c472df68e70a03facafa1bc0a8 |
- | salaries | 2844047 | fd220654e95aea1b169624ffe3fca934 |
- +--------------+------------------+----------------------------------+
- +--------------+---------------+-----------+
- | table_name | records_match | crc_match |
- +--------------+---------------+-----------+
- | employees | OK | ok |
- | departments | OK | ok |
- | dept_manager | OK | ok |
- | dept_emp | OK | ok |
- | titles | OK | ok |
- | salaries | OK | ok |
- +--------------+---------------+-----------+
employee组织结构图
Mysql导入SQL数据库提示Failed to open file 'load_departments.dump'
linux下:
- tar -xjf $HOME/Downloads/employees_db-full-1.0.4.tar.bz2
- //解压缩,进入目录
- cd employees_db/
- //导入数据库root为用户名
- mysql -t -u root -p < employees.sql
-
Windows下:
在MySQL命令窗口中,首先切换到employees_db目录下,然后输入命令:
F:\employees_db> mysql -t -u root -p < employees.sql
Mysql导入SQL数据库提示Failed to open file 'load_departments.dump'报错处理如下:
select 'LOADING employees' as 'INFO'; source D:\employees_db\load_employees.dump;
select 'LOADING departments' as 'INFO'; source D:\employees_db\load_departments.dump;
select 'LOADING dept_emp' as 'INFO'; source D:\employees_db\load_dept_emp.dump;
select 'LOADING titles' as 'INFO'; source D:\employees_db\load_titles.dump;
select 'LOADING salaries' as 'INFO'; source D:\employees_db\load_salaries.dump;
select 'LOADING dept_manager' as 'INFO'; source D:\employees_db\load_dept_manager.dump;