$ sudo apt install mysql-server
$ mysql --version mysql Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using EditLine wrapper
$ sudo mysql -u root
[sudo] password for mtitek: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.7.27-0ubuntu0.18.04.1 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> USE mysql;
mysql> SELECT user, host, plugin FROM user;
+------------------+-----------+-----------------------+ | user | host | plugin | +------------------+-----------+-----------------------+ | root | localhost | auth_socket | | mysql.session | localhost | mysql_native_password | | mysql.sys | localhost | mysql_native_password | | debian-sys-maint | localhost | mysql_native_password | +------------------+-----------+-----------------------+
$ sudo mysql_secure_installation
[sudo] password for mtitek: Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 25 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
$ ls -al /etc/mysql/
drwxr-xr-x root root mysql.conf.d -rw-r--r-- 1 root root mysqld.cnf -rw-r--r-- 1 root root mysqld_safe_syslog.cnf drwxr-xr-x root root conf.d -rw-r--r-- 1 root root mysql.cnf -rw-r--r-- 1 root root mysqldump.cnf -rw-r--r-- root root mysql.cnf lrwxrwxrwx root root my.cnf -> /etc/alternatives/my.cnf -rw-r--r-- root root my.cnf.fallback -rw------- root root debian.cnf -rwxr-xr-x root root debian-start
$ sudo ls -al /var/lib/mysql
-rw-r----- mysql mysql auto.cnf -rw-r--r-- root root debian-5.7.flag -rw-r----- mysql mysql ib_buffer_pool -rw-r----- mysql mysql ibdata1 -rw-r----- mysql mysql ib_logfile0 -rw-r----- mysql mysql ib_logfile1 -rw-r----- mysql mysql ibtmp1 drwxr-x--- mysql mysql mysql drwxr-x--- mysql mysql performance_schema drwxr-x--- mysql mysql sy
$ ls -al /var/log/mysql/
-rw-r----- mysql adm error.log
$ sudo mysql -u root
[sudo] password for mtitek:
$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
[mysql] #bind-address = 127.0.0.1 bind-address = 0.0.0.0
$ sudo service mysql restart
$ sudo mysql -u root
[sudo] password for mtitek:
mysql> status;
mysql Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using EditLine wrapper Connection id: 10 Current database: mysql Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.27-0ubuntu0.18.04.1 (Ubuntu) Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /var/run/mysqld/mysqld.sock
mysql> show variables like 'version';
+---------------+--------+ | Variable_name | Value | +---------------+--------+ | version | 5.7.27 | +---------------+--------+
$ echo "show variables like 'version';" | sudo mysql -u root
[sudo] password for mtitek: Variable_name Value version 5.7.27
mysql> select database();
+------------+ | database() | +------------+ | NULL | +------------+
mysql> select user();
+----------------+ | user() | +----------------+ | root@localhost | +----------------+
mysql> CREATE USER user1@localhost IDENTIFIED BY 'user1';
mysql> FLUSH PRIVILEGES;
mysql> CREATE USER user1@'%' IDENTIFIED BY 'user1';
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | LOW | | validate_password_special_char_count | 1 | +--------------------------------------+-------+
mysql> SET GLOBAL validate_password_length = 5;
mysql> SET GLOBAL validate_password_number_count = 0;
mysql> GRANT ALL ON mydb.* TO user1@localhost;
mysql> GRANT ALL ON mydb.* TO user1@'%';
mysql> DROP USER 'user1'@'localhost';
mysql> DROP USER 'user1'@'%';
mysql> use mysql;
mysql> select host, user from user;
mysql> select * from user;
$ mysql -h localhost -u user1 -p
$ mysql --host=localhost --user=user1 --password
$ mysql --host=localhost --user=user1 --password=user1
mysql> help create database;
mysql> CREATE DATABASE mydb DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
mysql> show databases;
+--------------------+ | Database | +--------------------+ | information_schema | | mydb | | mysql | | performance_schema | | sys | +--------------------+
mysql> use mysql;
mysql> select host, db, user from db;
mysql> select * from db;
mysql> use mydb;
mysql> select database();
+----------+ | Database | +----------+ | mydb | +----------+
mysql> drop database mydb;
mysql> create table table1 (id integer);
mysql> show tables;
mysql> select * from table1;
mysql> drop table table1;
mysql> mysqldump -u user1 -p -B mydb > user1-database-dump.sql
$ sudo mysql -u root
[sudo] password for mtitek:
mysql> SHOW STATUS WHERE variable_name like "Connection%";
+-----------------------------------+-------+ | Variable_name | Value | +-----------------------------------+-------+ | Connection_errors_accept | 0 | | Connection_errors_internal | 0 | | Connection_errors_max_connections | 0 | | Connection_errors_peer_address | 0 | | Connection_errors_select | 0 | | Connection_errors_tcpwrap | 0 | | Connections | 7 | +-----------------------------------+-------+
$ sudo mysql -u root
[sudo] password for mtitek:
mysql> SHOW processlist;
+----+------+-----------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------+------------------+ | 5 | root | localhost | NULL | Sleep | 596 | | NULL | | 6 | root | localhost | NULL | Query | 0 | init | SHOW processlist | +----+------+-----------+------+---------+------+-------+------------------+
mysql> kill 5
mysql> show variables like 'expire_logs_days';
+------------------+-------+ | Variable_name | Value | +------------------+-------+ | expire_logs_days | 10 | +------------------+-------+
mysql> set global expire_logs_days = 7;
expire_logs_days = 7;