Fix ERROR 1045: “Access denied for user…” in MySQL

If you’re getting error 1045 that reads something like “Access denied for user ‘root’@’localhost’“, it’s because you’re trying to log in to MySQL without the right credentials.

This usually happens when we provide the wrong password. But there could also be another cause. For example, we could be trying to do something as the root user that requires a password, but the root user hasn’t yet had its password set.

To fix this issue, be sure to provide the correct password when connecting to MySQL.

Continue reading

Fix ERROR 1050 (42S01) “Table … already exists” in MySQL

If you’re getting an error that reads something like “ERROR 1050 (42S01): Table ‘customers’ already exists” when trying to create a table in MySQL, it’s probably because there’s already a table in the database with the same name.

To fix this issue, either change the name of the table you’re trying to create, or check the existing table to see if it’s the one you actually need.

Continue reading

4 Ways to Clone a Table in MySQL

MySQL provides us with several ways to copy a database table. The method we use will depend on our requirements.

We can choose to copy the table, its data, and its indexes. Or we can copy just the table and data without the indexes. We can alternatively generate the code that will enable us to copy the table later.

Continue reading

7 Ways to Insert Multiple Rows in SQL

We can use the SQL INSERT statement to insert a row into a table. We can also use it to insert more than one row.

Below are seven ways to insert multiple rows into a table in SQL. Most of these examples should work in the major RDBMSs, with the possible exception of Oracle. But no worries, I’ve included an example just for Oracle.

Continue reading