In MySQL, SESSION_USER()
is a synonym for the USER()
function. It returns the current MySQL user name and host name, given when connecting to MySQL.
Category: MySQL
MySQL SYSTEM_USER() Explained
In MySQL, SYSTEM_USER()
is a synonym for the USER()
function. It returns the current MySQL user name and host name, given when connecting to MySQL.
How to Set Up Named Time Zones in MySQL
If you want to use named time zones in MySQL, you’ll need to make sure they’ve been configured.
By “named time zones”, I mean being able to use strings like US/Eastern
instead of −04:00
or −05:00
when specifying the time zone. For example, when using the CONVERT_TZ()
function.
Here’s how to configure named time zones in MySQL.
Continue readingFix 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 readingMySQL CURRENT_USER() Explained
In MySQL, CURRENT_USER()
is a built-in function that returns the user name and host name combination for the MySQL account that the server used to authenticate the current client.
MySQL USER() Explained
In MySQL, USER()
is a built-in function that returns the current MySQL user name and host name, given when connecting to MySQL.
The result is returned as a string in the utf8mb3
character set.
The value returned by USER()
could be different to the value returned by CURRENT_USER()
.
Create a Table if it Doesn’t Exist in SQL
When creating a table with SQL, we can specify that the table is only to be created if it doesn’t already exist. Doing this prevents any errors from occurring in the event that the table already exists.
Here are some examples of doing this in various RDBMSs.
Continue readingFix 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 readingHow to Insert Multiple Rows in SQL
When working with SQL, we can use the INSERT
statement to insert a new row into a table. But what if we want to insert more than one row?
Fortunately, we can still use the INSERT
statement. Below is a quick example that inserts multiple rows using SQL.
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