Browsed by
Tag: MySQL Tutorials

Write a query to display the current date and time?

Write a query to display the current date and time?

If you want to display the current date and time, use: SELECT NOW(); If you want to display the current date only, use: SELECT CURRENT_DATE(); To display the current date and time in MySQL, you can use the NOW() function. Here’s the query: SELECT NOW(); This will return the current date and time in the format ‘YYYY-MM-DD HH:MM:SS’.

What is the usage of regular expressions in MySQL?

What is the usage of regular expressions in MySQL?

In MySQL, regular expressions are used in queries for searching a pattern in a string. * Matches 0 more instances of the string preceding it. + matches one more instances of the string preceding it. ? Matches 0 or 1 instances of the string preceding it. . Matches a single character. [abc] matches a or b or z | separates strings ^ anchors the match from the start. “.” Can be used to match any single character. “|” can be…

Read More Read More

MySQL Interview Questions – Set 04

MySQL Interview Questions – Set 04

How to search second maximum(second highest) salary value(integer)from table employee (field salary)in the manner so that mysql gets less load? By below query we will get second maximum(second highest) salary value(integer)from table employee (field salary)in the manner so that mysql gets less load? SELECT DISTINCT(salary) FROM employee order by salary desc limit 1 , 1 ; (This way we will able to find out 3rd highest , 4th highest salary so on just need to change limit condtion like LIMIT…

Read More Read More

How to dump a table from a database

How to dump a table from a database

# [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql To dump a table from a MySQL database, you can use the mysqldump command-line tool. Here’s the basic syntax: bash mysqldump -u [username] -p [password] [database_name] [table_name] > [output_file.sql] Replace [username] with your MySQL username, [password] with your MySQL password, [database_name] with the name of the database containing the table you want to dump, [table_name] with the name of the table you want to dump, and [output_file.sql] with the…

Read More Read More

How to change the database name in MySQL?

How to change the database name in MySQL?

Sometimes we need to change or rename the database name because of its non-meaningful name. To rename the database name, we need first to create a new database into the MySQL server. Next, MySQL provides the mysqldump shell command to create a dumped copy of the selected database and then import all the data into the newly created database. The following is the syntax of using mysqldump command: mysqldump -u username -p “password” -R oldDbName > oldDbName.sql Now, use the…

Read More Read More

How to create a new user in MySQL?

How to create a new user in MySQL?

A USER in MySQL is a record in the USER-TABLE. It contains the login information, account privileges, and the host information for MySQL account to access and manage the databases. We can create a new user account in the database server using the MySQL Create User statement. It provides authentication, SSL/TLS, resource-limit, role, and password management properties for the new accounts. The following is the basic syntax to create a new user in MySQL: CREATE USER [IF NOT EXISTS] account_name…

Read More Read More

What are the advantages of MySQL in comparison to Oracle?

What are the advantages of MySQL in comparison to Oracle?

MySQL is a free, fast, reliable, open-source relational database while Oracle is expensive, although they have provided Oracle free edition to attract MySQL users. MySQL uses only just under 1 MB of RAM on your laptop, while Oracle 9i installation uses 128 MB. MySQL is great for database enabled websites while Oracle is made for enterprises. MySQL is portable.

What is the save point in MySQL?

What is the save point in MySQL?

A defined point in any transaction is known as savepoint. SAVEPOINT is a statement in MySQL, which is used to set a named transaction savepoint with the name of the identifier. A savepoint in MySQL is a point within a transaction where you can roll back to if needed. It allows you to set a named marker within a transaction so that you can later roll back to that specific point if necessary, rather than rolling back the entire transaction….

Read More Read More

What is the usage of the “i-am-a-dummy” flag in MySQL?

What is the usage of the “i-am-a-dummy” flag in MySQL?

In MySQL, the “i-am-a-dummy” flag makes the MySQL engine to deny the UPDATE and DELETE commands unless the WHERE clause is present. The “i-am-a-dummy” flag in MySQL is a humorous option that can be used as a safety measure. When enabled, it prevents accidental updates or deletes on a table by issuing an error message instead. It’s often used in development or testing environments to avoid unintentional data modifications. However, it’s not typically used in production environments due to its…

Read More Read More

MySQL Interview Questions – Set 05

MySQL Interview Questions – Set 05

How will Show all records containing the name “sonia” AND the phone number ‘9876543210’ mysql> SELECT * FROM tablename WHERE name = “sonia” AND phone_number = ‘9876543210’ How to Update database permissions/privilages. mysql> flush privileges; how to Return total number of rows mysql> SELECT COUNT(*) FROM tablename; How to dump one database for backup. # [mysql dir]/bin/mysqldump -u username -ppassword –databases databasename >/tmp/databasename.sql How to delete a database from mysql server mysql> drop database databasename; How to Set a root…

Read More Read More