To create a MySQL table, first you need to log into your MariaDB or mySQL server or configure passwordless authentication and then use the -e command line option and the user must have the Insert_priv.
Use the show databases command to view the databases you have already created.
Something like this should be returned.
+--------------------+ | Database | +--------------------+ | information_schema | | db001 | | mysql | | performance_schema | +--------------------+
Enter the database you wish to use. In this example, the database named db001 will be used.
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;