Posts Tagged ‘mysql’

The basic steps in accessing a MySQL database is normally to connect, execute statement, fetch result, and then to close the connection. The following is the steps translated into Python codes;

# Import required module
import MySQLdb

# Connect
conn = MySQLdb.connect(host="localhost", port=3306, user="root", passwd="root123", db="mysql")
cursor = conn.cursor(  )

# Execute statement
stmt = "SELECT * FROM user"
cursor.execute(stmt)

# Fetch and output [...]

The first step in resetting MySQL password is a a matter of stopping the running MySQL instance, and run it in safe mode. This can be achieved by the following command;

# /etc/init.d/mysql stop
$ sudo mysqld_safe –skip-grant-tables

Next is to login to MySQL and select the database mysql;

$ mysql -u root
mysql> use mysql

And then the password can [...]


Categories