Browsed by
Tag: Interview Questions on MySQL

How to Update a root password

How to Update a root password

# mysqladmin -u root -p oldpassword newpassword To update the root password in MySQL, you can follow these steps: Log in to MySQL as the root user: bash mysql -u root -p Enter the current root password when prompted. Once logged in, use the following SQL command to update the root password: sql ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘new_password’; Replace ‘new_password’ with your desired new password. After updating the password, flush the privileges to apply the changes: sql FLUSH PRIVILEGES;…

Read More Read More

How we get Sum of column

How we get Sum of column

mysql> SELECT SUM(*) FROM [table name]; To get the sum of a column in MySQL, you can use the SUM() function. Here’s the basic syntax: sql SELECT SUM(column_name) FROM table_name; Replace column_name with the name of the column for which you want to calculate the sum, and table_name with the name of the table where the column is located. For example, if you have a table named sales and you want to find the sum of the amount column, the…

Read More Read More

How to allow the user “sonia” to connect to the server from localhost using the password “passwd”. Login as root.

How to allow the user “sonia” to connect to the server from localhost using the password “passwd”. Login as root.

How to allow the user “sonia” to connect to the server from localhost using the password “passwd”. Login as root. Switch to the MySQL db. Give privs. Update privs # mysql -u root -p mysql> use mysql; mysql> grant usage on *.* to sonia@localhost identified by ‘passwd’; mysql> flush privileges; To allow the user “sonia” to connect to the MySQL server from localhost using the password “passwd” and grant necessary privileges, you can follow these steps: Log in to MySQL…

Read More Read More

How to delete a table

How to delete a table

mysql> drop table tablename; In MySQL, you can delete a table using the DROP TABLE statement. Here’s the basic syntax: sql DROP TABLE table_name; Replace table_name with the name of the table you want to delete. Be cautious when using this statement, as it permanently removes the table and all of its data. Make sure to have a backup if needed. Example: sql DROP TABLE mytable; This will delete the table named “mytable” from the database.

How to give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs

How to give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs

# mysql -u root -p # mysql -u root -p mysql> use mysql; mysql> INSERT INTO user (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES (‘%’,’databasename’,’username’,’Y’,’Y’,’Y’,’Y’,’Y’,’N’); mysql> flush privileges; or mysql> grant all privileges on databasename.* to username@localhost; mysql> flush privileges To give user privileges for a specific database in MySQL, you would typically follow these steps: Login as root: Use the mysql command-line tool to log in as the root user, providing the appropriate credentials. bash mysql -u root -p Switch to the MySQL database:…

Read More Read More

How you will Show all data from a table.

How you will Show all data from a table.

mysql> SELECT * FROM tablename; To show all data from a table in MySQL, you can use the SELECT statement. The basic syntax is as follows: sql SELECT * FROM your_table_name; Replace your_table_name with the actual name of your table. The * is a wildcard character that represents all columns in the table. For example, if you have a table named “employees,” the query would be: sql SELECT * FROM employees; This query will retrieve all rows and columns from…

Read More Read More

How to update info already in a table and Delete a row(s) from a table

How to update info already in a table and Delete a row(s) from a table

mysql> UPDATE [table name] SET Select_priv = ‘Y’,Insert_priv = ‘Y’,Update_priv = ‘Y’ where [field name] = ‘user’; mysql> DELETE from [table name] where [field name] = ‘whatever’; To update information already in a MySQL table, you can use the UPDATE statement. Here’s the syntax: sql UPDATE table_name SET column1 = value1, column2 = value2, … WHERE condition; This will update the values in the specified columns for the rows that meet the specified condition. To delete row(s) from a MySQL…

Read More Read More

Introduction to MySQL

Introduction to MySQL

Introduction Note: “MySQL” it third party (“sun micro system”) C:\mysql –u root Types of Table (Engine) MyISAM: Foreign key constraint does not support InnoDB: used to support foreign key constraint BDB: support for UNIX environment Heap: it is temporary or virtual table, which is created only in memory not in hard disk Merge: it is used, if we want to merge more than one table (it is also temporary or virtual table) Syntax: Create table list ( — , —…

Read More Read More

How to Show certain selected rows with the value “pcds”

How to Show certain selected rows with the value “pcds”

mysql> SELECT * FROM tablename WHERE fieldname = “pcds”; To show certain selected rows with the value “pcds” in MySQL, you can use the SELECT statement with a WHERE clause. Here’s an example: sql SELECT * FROM your_table_name WHERE your_column_name = ‘pcds’; Replace your_table_name with the actual name of your table and your_column_name with the column where you want to find the value “pcds.” For instance, if you have a table named example_table and a column named example_column, the query…

Read More Read More

How to Update database permissions/privilages

How to Update database permissions/privilages

mysql> flush privileges; To update database permissions or privileges in MySQL, you typically use the GRANT and REVOKE statements. Here’s how you can do it: Granting Permissions: To grant permissions to a user, you can use the GRANT statement followed by the specific privileges and the database or tables the user should have access to. For example: sql GRANT SELECT, INSERT ON mydatabase.* TO ‘myuser’@’localhost’; This grants the SELECT and INSERT privileges on all tables in the mydatabase database to…

Read More Read More