Instalacion PhpMyAdmin - mergutm/databasecourse_utm GitHub Wiki

For every step you can run all commands as root, if not, prefix all instructions with sudo in order to execute as sudo user.

Log in as root

sudo su

Update packages

apt-get update

install mysql-server

# aptitude install mysql-server
The following NEW packages will be installed:
  libaio1{a} libcgi-fast-perl{a} libcgi-pm-perl{a} libevent-core-2.1-7{a} libevent-pthreads-2.1-7{a} libfcgi-bin{a} libfcgi-perl{a} 
  libfcgi0ldbl{a} libhtml-template-perl{a} libmecab2{a} libprotobuf-lite23{a} mecab-ipadic{a} mecab-ipadic-utf8{a} mecab-utils{a} 
  mysql-client-8.0{a} mysql-client-core-8.0{a} mysql-common{a} mysql-server mysql-server-8.0{a} mysql-server-core-8.0{a} 
0 packages upgraded, 20 newly installed, 0 to remove and 74 not upgraded.
Need to get 29.2 MB of archives. After unpacking 242 MB will be used.
Do you want to continue? [Y/n/?] y
Get: 1 http://mx.archive.ubuntu.com/ubuntu jammy/main amd64 mysql-common all 5.8+1.0.8 [7 212 B]
Get: 2 http://mx.archive.ubuntu.com/ubuntu jammy-updates/main amd64 mysql-client-core-8.0 amd64 8.0.32-0ubuntu0.22.04.2 [2 677 kB]

Config mysql

[sudo]  mysql

Update mysql password

alter user 'root'@'localhost' identified with mysql_native_password by 'utm2023';

exit mysql

exit
mysql_secure_installation 

Securing the MySQL server deployment.

Enter password for user root: 

VALIDATE PASSWORD COMPONENT 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 component?

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
Using existing password for root.

Estimated strength of the password: 25 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
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) : y
Success.

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) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

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! 

Create user

run on the terminal

mysql -u root -p

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.32-0ubuntu0.22.04.2 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database examenes;
Query OK, 1 row affected (0.06 sec)

mysql>  

Create the database examenes:

create database examenes;

Show the created database:

show schemas

Create a user with privileges

if first sentence generates an error, execute the same with a stronger password, like the second one

create user 'admin' @'localhost' identified with mysql_native_password by 'utm2023'; 
create user 'admin' @'localhost' identified with mysql_native_password by 'UTM$compu@2023';	
Query OK, 0 rows affected (0.04 sec)

Review the created user by reading the database mysql wich contains all existing users.

USE mysql ; 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

Show all contained tables in mysql database:

SHOW TABLES;
+------------------------------------------------------+
| Tables_in_mysql                                      |
+------------------------------------------------------+
| columns_priv                                         |
| component                                            |
| db                                                   |

List of users in MySQL

SELECT  user FROM user;
+------------------+
| user             |
+------------------+
| admin            |
| debian-sys-maint |
| mysql.infoschema |
| mysql.session    |
| mysql.sys        |
| root             |
+------------------+
6 rows in set (0.01 sec)

Grant privileges to use examenes database to user admin

GRANT ALL ON examenes.*  to 'admin'@'localhost' ;

Install PHP and PhpMyAdmin

Install PHP

aptitude install php
The following NEW packages will be installed:
  apache2{a} apache2-bin{a} apache2-data{a} apache2-utils{a} libapache2-mod-php8.1{a} libapr1{a} libaprutil1{a} libaprutil1-dbd-sqlite3{a} 
  libaprutil1-ldap{a} php php-common{a} php8.1{a} php8.1-cli{a} php8.1-common{a} php8.1-opcache{a} php8.1-readline{a} 
0 packages upgraded, 16 newly installed, 0 to remove and 74 not upgraded.
Need to get 7 046 kB of archives. After unpacking 29.0 MB will be used.
Do you want to continue? [Y/n/?] y
Get: 1 http://mx.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libapr1 amd64 1.7.0-8ubuntu0.22.04.1 [108 kB]
Get: 2 http://mx.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libaprutil1 amd64 1.6.1-5ubuntu4.22.04.1 [92.6 kB]
Get: 3 http://mx.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-5ubuntu4.22.04.1 [11.3 kB]
...

Install phpmyadmin

aptitude install phpmyadmin

Review the access, open in a browser

He creado el siguiente usuario para pruebas en el servidor:

revisar el siguiente link: Creación de usuarios en MySQL


CREATE USER 'usuario'@'localhost' IDENTIFIED WITH mysql_native_password BY 'UTM=compu@2023';
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT on 'pruebas'.* TO 'usuario'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

SHOW GRANTS FOR 'usuario'@'localhost'