View Single Post
Old 05-31-2014, 06:52 PM  
Barry-xlovecam
It's 42
 
Industry Role:
Join Date: Jun 2010
Location: Global
Posts: 18,083
http://dev.mysql.com/doc/refman/5.1/en/load-data.html

Just make the data for the table fields from the excel to a CSV file
FTP the CSV file to the server location that you want (remote server)
Open a terminal or ssh (remote server) windows putty.exe works well in linux use ssh direct from the terminal.

Use mysqlmonitor.

example:
Code:
~$:mysql -u userName -p
Enter password:*******

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| TUTORIALS          |
| mysql              |
| mydatabase               |
+--------------------+

 mysql> use mydatabase;

Database changed

mysql> load data LOCAL infile '/home/user/zip_data/zip5.csv' into table zip_location_data fields terminated by ',' lines terminated by '\n' (zip, city, state, lat, lng, county);
Query OK, 41755 rows affected (0.13 sec)
Records: 41755  Deleted: 0  Skipped: 0  Warnings: 0
That fast enough

You need to make the fields in the csv file's lines in the scope of the table's fields (the field's column names) that you are loading the data into.

if you select the database then
mysql>show tables;

mysql>describe 'tableName';

that will give you the field name and schema.

example:

Quote:
mysql> use mydatabase;

Database changed

mysql> show tables;
+-------------------+
| Tables_in_mydatabase |
+-------------------+
| ***** |
| **** |
| ***_**** |
| sic |
| zip_location_data |
+-------------------+
5 rows in set (0.02 sec)

mysql> describe zip_location_data;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| zip | varchar(60) | NO | | NULL | |
| city | varchar(80) | NO | | NULL | |
| state | varchar(80) | NO | | NULL | |
| lat | float(10,6) | NO | | NULL | |
| lng | float(10,6) | NO | | NULL | |
| county | varchar(80) | NO | | NULL | |
+--------+-------------+------+-----+---------+----------------+
7 rows in set (0.03 sec)
You will notice in the CSV fields descriptors above that 'id' is omitted -- it is auto_increment, the mysql server makes the entry: 1,2,3, ...400 etc id is the primary key for look ups etc. .

A wordpress installation test I did (older version)
Code:
mysql> use planet;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+--------------------------+
| Tables_in_planet         |
+--------------------------+
| wp001_commentmeta        |
| wp001_comments           |
| wp001_links              |
| wp001_options            |
| wp001_postmeta           |
| wp001_posts              |
| wp001_term_relationships |
| wp001_term_taxonomy      |
| wp001_terms              |
| wp001_usermeta           |
| wp001_users              |
+--------------------------+
11 rows in set (0.00 sec)

mysql> describe wp001_posts;
+-----------------------+---------------------+------+-----+---------------------+----------------+
| Field                 | Type                | Null | Key | Default             | Extra          |
+-----------------------+---------------------+------+-----+---------------------+----------------+
| ID                    | bigint(20) unsigned | NO   | PRI | NULL                | auto_increment |
| post_author           | bigint(20) unsigned | NO   | MUL | 0                   |                |
| post_date             | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_date_gmt         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_content          | longtext            | NO   |     | NULL                |                |
| post_title            | text                | NO   |     | NULL                |                |
| post_excerpt          | text                | NO   |     | NULL                |                |
| post_status           | varchar(20)         | NO   |     | publish             |                |
| comment_status        | varchar(20)         | NO   |     | open                |                |
| ping_status           | varchar(20)         | NO   |     | open                |                |
| post_password         | varchar(20)         | NO   |     |                     |                |
| post_name             | varchar(200)        | NO   | MUL |                     |                |
| to_ping               | text                | NO   |     | NULL                |                |
| pinged                | text                | NO   |     | NULL                |                |
| post_modified         | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_modified_gmt     | datetime            | NO   |     | 0000-00-00 00:00:00 |                |
| post_content_filtered | text                | NO   |     | NULL                |                |
| post_parent           | bigint(20) unsigned | NO   | MUL | 0                   |                |
| guid                  | varchar(255)        | NO   |     |                     |                |
| menu_order            | int(11)             | NO   |     | 0                   |                |
| post_type             | varchar(20)         | NO   | MUL | post                |                |
| post_mime_type        | varchar(100)        | NO   |     |                     |                |
| comment_count         | bigint(20)          | NO   |     | 0                   |                |
+-----------------------+---------------------+------+-----+---------------------+----------------+
23 rows in set (0.00 sec)

mysql> select * from wp001_posts;
+----+-------------+---------------------+---------------------+--------------------------------------------------------------------------------------------------------------------------------------
| ID | post_author | post_date           | post_date_gmt       | post_content|ping_status | post_password | post_name   | to_ping | pinged | post_modified       | post_modified_gmt   | post_content_filtered | post_parent | guid | menu_order | post_type | post_mime_type | comment_count |
----------+----------------+-------------+---------------+-------------+---------+--------+---------------------+---------------------+-----------------------+-------------+------------------------------------------------------------+------------+-----------+----------------+---------------+
|  1 |           1 | 2011-05-11 18:29:53 | 2011-05-11 18:29:53 | Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!  | Hello world! |              | publish     | open           | open        |               | hello-world |         |        | 2011-05-11 18:29:53 | 2011-05-11 18:29:53 |                       |           0 | http://www.****.com/wordpress_design/?p=1       |          0 | post      |                |             1 |
too long:(
5 rows in set (0.04 sec)

mysql>
Have fun
Barry-xlovecam is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook