Installing a new database server: Difference between revisions
Jump to navigation
Jump to search
Created page with "= Packages = <pre> apt-get install mysql-server phpmyadmin </pre> From Debian 9 this will install MariaDB = Initial setup = run <pre> mysql_secure_installation </pre> to set..." |
No edit summary |
||
Line 21: | Line 21: | ||
</pre> | </pre> | ||
= Create a new database = | = Common Commands = | ||
== Create a new database == | |||
<pre> | <pre> | ||
create user user@localhost identified by 'somepass'; | create user user@localhost identified by 'somepass'; | ||
Line 28: | Line 29: | ||
flush privileges; | flush privileges; | ||
</pre> | </pre> | ||
== Allow connections from other hosts == | |||
Preferably set % to a specific IP address | |||
<pre> | |||
use mysql; | |||
update user set Host='%' where User='username'; | |||
update db set Host='%' where Db='dbname'; | |||
flush privileges; | |||
</pre> | |||
== Changing a user password == | |||
<pre> | |||
UPDATE user SET Password=PASSWORD('my_password') where USER='username'; | |||
flush privileges; | |||
</pre> | |||
== Delete a database == | |||
<pre> | |||
drop database dbname; | |||
</pre> | |||
Don't forget to delete the database and user from the mysql User and Db tables |
Revision as of 08:23, 30 August 2017
Packages
apt-get install mysql-server phpmyadmin
From Debian 9 this will install MariaDB
Initial setup
run
mysql_secure_installation
to set up a root password and delete the test database
notes on root
Nowadays when you are logged in to bash as root, you can enter mariadb by just running mariadb / mysql and will not be prompted for a password! However, you can also not enter mysql as root from another user or from phpmyadmin! [1]
So to fix this, we enter mysql and do:
update mysql.user set plugin = 'mysql_native_password' where User='root'; flush privileges;
Common Commands
Create a new database
create user user@localhost identified by 'somepass'; create database dbname; grant all on dbname.* to user@localhost; flush privileges;
Allow connections from other hosts
Preferably set % to a specific IP address
use mysql; update user set Host='%' where User='username'; update db set Host='%' where Db='dbname'; flush privileges;
Changing a user password
UPDATE user SET Password=PASSWORD('my_password') where USER='username'; flush privileges;
Delete a database
drop database dbname;
Don't forget to delete the database and user from the mysql User and Db tables