To create a MySQL table, first you need to sign into your MySQL server. First you will need to sign into your MySQL account. Next, you need to enter the database you want to use. Use the show databases command to view the databases you have already established.
You need to enter the database you wish to use. If the database you wish to use already exists, use the use database command. If the database you wish to use does not exist, use the create database command.
use database databasename; create database databasename;
The following syntax is used to insert data into a table.
insert into tablename ->(columnname, columnname, columnname) ->values ->("data", "data", "data"); Query OK, 1 row affected, 0 warnings (0.00 sec)
To verify that the data was successfully inserted, enter this command:
select * from tablename;
If we have a large amount of data, entering the data one by one in the Terminal is impractical to impossible. We can enter the data into a TXT file, and then import the TXT file into MySQL. The data should be separated by tab. For cells that should have no data, use \ in the TXT file. For example, let's say the table in our database has these columns:
In our TXT file, we could have something like this:
Google email@example.com supersecretpassword youtube
Facebook firstname.lastname@example.org supersecretpassword \
Twitter JeremyC supersecretpassword \
Let's say we save this TXT file at /home/usernames.txt. Sign into your MySQL server. Then, enter the table you want to load the data into. Then, use the load data command to insert the data from the TXT file into MySQL.
use tablename; load data infile '/home/usernames.txt' into table tablename;