Bootstrap FreeKB - mySQL / MariaDB - Insert a row into a table
mySQL / MariaDB - Insert a row into a table

Updated:   |  mySQL / MariaDB articles

The insert command can be used to add a row to a table. You will first 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 Alter_priv.

One option is to first issue the use <database name> command and to then issue the insert command.

use db001; insert into table001 (name, date) values ("John Doe", "2022-01-10");


Or like this.

insert into db001.table001 (name, date) values ("John Doe", "2022-01-10");


To verify that the data was successfully inserted, enter this command:

select * from db001.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:

  • site
  • username
  • password
  • note

In our TXT file, we could have something like this:

Google     supersecretpassword     youtube 

Facebook     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;


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee


Add a Comment

Please enter d3f81d in the box below so that we can be sure you are a human.