Browsed by
Category: Blog

Restore database (or database table) from backup

Restore database (or database table) from backup

# [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql To restore a database or a specific table from a backup in MySQL, you typically use the mysql command-line client or a similar tool. Here’s a general approach: Ensure you have a backup: First, make sure you have a recent backup of the database or table you want to restore. Access the MySQL command-line interface: Open your terminal or command prompt and log in to MySQL using a command like: css…

Read More Read More

How to do login in mysql with unix shell

How to do login in mysql with unix shell

By below method if password is pass and user name is root # [mysql dir]/bin/mysql -h hostname -u root -p pass To log in to MySQL using the Unix shell, you can use the mysql command along with the appropriate options. Here’s the general syntax: bash mysql -u your_username -p Replace your_username with your MySQL username. After running this command, you will be prompted to enter your MySQL password. Once you provide the correct password, you’ll be logged into the…

Read More Read More

How to Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs

How to Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs

# mysql -u root -p mysql> use mysql; mysql>INSERTINTO user (Host,User,Password) VALUES(‘%’,’username’,PASSWORD(‘password’)); mysql> flush privileges; To create a new user in MySQL, you can follow these steps: Login as root: bash mysql -u root -p You will be prompted to enter the root password. Switch to the MySQL database: sql USE mysql; Create the new user: sql CREATE USER ‘new_user’@’localhost’ IDENTIFIED BY ‘password’; Replace ‘new_user’ with the desired username and ‘password’ with the desired password. Update privileges: sql GRANT ALL…

Read More Read More

How to Create Table show Example

How to Create Table show Example

mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255)); To create a table in MySQL, you can use the CREATE TABLE statement followed by the table name and the list of columns with their data types and any constraints. Here’s an example: sql CREATE TABLE employees ( employee_id INT AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100) UNIQUE, hire_date DATE, salary DECIMAL(10, 2), department_id INT );…

Read More Read More

How you will Create a database on the mysql server with unix shell

How you will Create a database on the mysql server with unix shell

mysql> create database databasename; To create a MySQL database on a server using the Unix shell, you can use the mysqladmin or mysql command-line tools. Here’s an example using the mysql command: Open a terminal on your Unix-based system. Log in to the MySQL server using the following command. You will be prompted to enter the MySQL user password. bash mysql -u username -p Replace “username” with your MySQL username. Once you are logged in, you can create a new…

Read More Read More

How to Change a users password from unix shell

How to Change a users password from unix shell

# [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password ‘new-password’ To change a user’s password in MySQL from the MySQL prompt while logged in as the root user, you can use the following steps: To change a MySQL user’s password from the Unix shell, you can use the mysqladmin command. Here’s an example: bash mysqladmin -u <username> -p password <new_password> Replace <username> with the actual username for which you want to change the password, and <new_password> with the desired new…

Read More Read More

Use a regular expression to find records. Use “REGEXP BINARY” to force case-sensitivity. This finds any record beginning with r

Use a regular expression to find records. Use “REGEXP BINARY” to force case-sensitivity. This finds any record beginning with r

mysql> SELECT * FROM tablename WHERE rec RLIKE “^r”; To find records beginning with “r” in MySQL with case sensitivity enforced, you would use the following query: sql SELECT * FROM your_table WHERE your_column REGEXP BINARY ‘^r’; This query uses the REGEXP BINARY operator to enforce case sensitivity, and ^r as the regular expression pattern to match any record beginning with “r”.

How to list or view all databases from the mysql server

How to list or view all databases from the mysql server

mysql> show databases. To list or view all databases in MySQL, you can use the following SQL command: sql SHOW DATABASES; When you run this command in the MySQL command-line interface or any MySQL client tool, it will display a list of all the databases available on the MySQL server.

How to Change a users password from MySQL prompt. Login as root. Set the password. Update privs

How to Change a users password from MySQL prompt. Login as root. Set the password. Update privs

# mysql -u root -p mysql> SET PASSWORD FOR ‘user’@’hostname’ = PASSWORD(‘passwordhere’); mysql> flush privileges; To change a user’s password in MySQL from the MySQL prompt while logged in as the root user, you can use the following steps: Log in to MySQL as the root user: sql mysql -u root -p You will be prompted to enter the root password. Change the user’s password: sql ALTER USER ‘username’@’host’ IDENTIFIED BY ‘new_password’; Replace ‘username’ with the actual username, ‘host’ with…

Read More Read More

How Switch (select or use) to a database

How Switch (select or use) to a database

mysql> use databasename; In MySQL, you can switch (select or use) to a different database using the USE statement. Here’s the syntax: sql USE database_name; Replace database_name with the name of the database you want to switch to. This statement sets the default database for the current session. For example, if you want to switch to a database called “mydatabase,” you would execute: sql USE mydatabase; After executing this statement, any subsequent SQL statements will be executed in the context…

Read More Read More