Browsed by
Category: Blog

How to Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables.

How to Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables.

How to Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server # /etc/init.d/mysql stop # mysqld_safe –skip-grant-tables & # mysql -u root mysql> use mysql; mysql> update user set password=PASSWORD(“newrootpassword”) where User=’root’; mysql> flush privileges; mysql> quit # /etc/init.d/mysql stop # /etc/init.d/mysql start Yes, the steps you provided are generally correct for recovering a MySQL root password. Here’s a…

Read More Read More

How to see all the tables from a database of mysql server

How to see all the tables from a database of mysql server

mysql> show tables; To see all the tables in a MySQL database, you can use the following SQL query: sql SHOW TABLES; This query will display a list of all tables in the currently selected database. If you want to see tables from a specific database, you can switch to that database using the USE statement before running the SHOW TABLES query. For example: sql USE your_database_name; SHOW TABLES; Replace your_database_name with the name of the database you want to…

Read More Read More

How to set a root password if there is on root password

How to set a root password if there is on root password

# mysqladmin -u root password newpassword If you want to set a root password for MySQL when there is no root password, you can follow these steps: Login to MySQL as the root user (without a password): bash mysql -u root Set a new password for the root user: sql ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘your_new_password’; Replace your_new_password with the desired password. Flush privileges to apply the changes: sql FLUSH PRIVILEGES; Exit the MySQL shell: sql exit; After completing these…

Read More Read More

How to see table’s field formats or description of table

How to see table’s field formats or description of table

mysql> describe tablename; In MySQL, you can use the DESC or DESCRIBE statement to see the description of a table, including the field formats. Here’s an example: sql DESCRIBE your_table_name; or sql DESC your_table_name; Replace “your_table_name” with the actual name of the table you want to describe. This will provide information about the columns, their data types, whether they allow NULL values, and any additional attributes. For example: sql DESCRIBE employees; This will show you the structure and details of…

Read More Read More

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