-
Notifications
You must be signed in to change notification settings - Fork 1
Setting up MySQL
Neil Cook edited this page Nov 9, 2020
·
2 revisions
Following guide here
Install MySQL by the following command:
>>> sudo apt-get install mysql-server
The MySQL server is started automatically after installation. You can check the status of the MySQL server with the following command:
>>> sudo service mysql status
Stop the MySQL server with the following command:
>>> sudo service mysql stop
To restart the MySQL server, use the following command:
>>> sudo service mysql start
Set the root password
>>> sudo mysql_secure_installation
To test:
>>> sudo mysql -u root -p
To add user
>>> sudo mysql -u root -p
>>> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
>>> GRANT ALL PRIVILEGES ON *.* to 'newuser'@'localhost';
>>> FLUSH PRIVILEGES;
From here
Connect via:
>>> mysql -h host -u user -p
Install via pip
pip install mysql-connector-python
Using in python
import mysql.connector as mysql
db = mysql.connect(host='localhost', user='newuser', passwd='password')
Note: DO NOT install mysql-connector
(it must be mysql-connector-python
)