Learn MySQL Topics : Security, Backups, Replication, Architecture, Install, Update, Ect. Flashcards
Authentication Plugins
1 Native Pluggable Authentication
2 Caching SHA-2 Pluggable Authentication
3 SHA-256 Pluggable Authentication
4 Client-Side Cleartext Pluggable Authentication
5 PAM Pluggable Authentication
6 Windows Pluggable Authentication
7 LDAP Pluggable Authentication
8 6.4.1.8 No-Login Pluggable Authentication
9 Socket Peer-Credential Pluggable Authentication
The MySQL 8.0 default plugin is indicated by the value of the default_authentication_plugin system variable.
mysql> show variables like ‘default_authentication_plugin’;
+——————————-+———————–+
| Variable_name | Value |
+——————————-+———————–+
| default_authentication_plugin | caching_sha2_password |
+——————————-+———————–+
1 row in set (0.00 sec)
Installing Native Pluggable Authentication
The mysql_native_password plugin exists in server and client forms:
The server-side plugin is built into the server, need not be loaded explicitly, and cannot be disabled by unloading it.
The client-side plugin is built into the libmysqlclient client library and is available to any program linked against libmysqlclient.
Using Native Pluggable Authentication
MySQL client programs use mysql_native_password by default. The –default-auth option can be used as a hint about which client-side plugin the program can expect to use:
shell> mysql –default-auth=mysql_native_password …
Pluggable authentication enables these important capabilities:
Choice of authentication methods
External authentication.
Proxy users
Pluggable authentication enables these important capabilities:
Choice of authentication methods. Pluggable authentication makes it easy for DBAs to choose and change the authentication method used for individual MySQL accounts.
External authentication. Pluggable authentication makes it possible for clients to connect to the MySQL server with credentials appropriate for authentication methods that store credentials elsewhere than in the mysql.user system table. For example, plugins can be created to use external authentication methods such as PAM, Windows login IDs, LDAP, or Kerberos.
Proxy users: If a user is permitted to connect, an authentication plugin can return to the server a user name different from the name of the connecting user, to indicate that the connecting user is a proxy for another user (the proxied user). While the connection lasts, the proxy user is treated, for purposes of access control, as having the privileges of the proxied user. In effect, one user impersonates another.
Pluggable Authentication
If you start the server with the –skip-grant-tables option, authentication plugins are not used even if loaded because the server performs no client authentication and permits any client to connect. Because this is insecure, if the server is started with the –skip-grant-tables option, it also disables remote connections by enabling skip_networking.
This option generally is only used if you forget the root password and need to reset it.
you must shutdown the MySQL database instance.
Then edit the my.cnf file to add:
[mysqld]
skip-grant-tables
Save and exit.
Start the service again and you should be able to log into your database without a password.
PAM Pluggable Authentication
PAM pluggable authentication is an extension included in MySQL Enterprise Edition, a commercial product.
MySQL Enterprise Edition supports an authentication method that enables MySQL Server to use PAM (Pluggable Authentication Modules) to authenticate MySQL users. PAM enables a system to use a standard interface to access various kinds of authentication methods, such as traditional Unix passwords or an LDAP directory.
PAM pluggable authentication provides these capabilities:
External authentication:
Proxy user support:
PAM pluggable authentication provides these capabilities:
External authentication: PAM authentication enables MySQL Server to accept connections from users defined outside the MySQL grant tables and that authenticate using methods supported by PAM.
Proxy user support: PAM authentication can return to MySQL a user name different from the external user name passed by the client program, based on the PAM groups the external user is a member of and the authentication string provided. This means that the plugin can return the MySQL user that defines the privileges the external PAM-authenticated user should have. For example, an operating system user named joe can connect and have the privileges of a MySQL user named developer.
Plugin and Library Names for PAM Authentication
Plugin and Library Names for PAM Authentication
Server-side plugin authentication_pam
Client-side plugin mysql_clear_password
Library file authentication_pam.so
PAM Authentication and libmysqlclient client library
The client-side mysql_clear_password cleartext plugin that communicates with the server-side PAM plugin is built into the libmysqlclient client library and is included in all distributions, including community distributions. Inclusion of the client-side cleartext plugin in all MySQL distributions enables clients from any distribution to connect to a server that has the server-side PAM plugin loaded.
Installing PAM Pluggable Authentication
To be usable by the server, the plugin library file must be located in the MySQL plugin directory (the directory named by the plugin_dir system variable). If necessary, configure the plugin directory location by setting the value of plugin_dir at server startup.
The plugin library file base name is authentication_pam. The file name suffix differs per platform (for example, .so for Unix and Unix-like systems, .dll for Windows).
To load the plugin at server startup, use the –plugin-load-add option to name the library file that contains it. With this plugin-loading method, the option must be given each time the server starts. For example, put these lines in the server my.cnf file, adjusting the .so suffix for your platform as necessary:
[mysqld]
plugin-load-add=authentication_pam.so
After modifying my.cnf, restart the server to cause the new settings to take effect.
Alternatively, to load the plugin at runtime, use this statement, adjusting the .so suffix for your platform as necessary:
INSTALL PLUGIN authentication_pam SONAME ‘authentication_pam.so’;
INSTALL PLUGIN loads the plugin immediately, and also registers it in the mysql.plugins system table to cause the server to load it for each subsequent normal startup without the need for –plugin-load-add.
To verify plugin installation, examine the INFORMATION_SCHEMA.PLUGINS table or use the SHOW PLUGINS statement
mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE '%pam%'; \+--------------------+---------------+ | PLUGIN_NAME | PLUGIN_STATUS | \+--------------------+---------------+ | authentication_pam | ACTIVE | \+--------------------+---------------+
Native Pluggable Authentication
MySQL includes a mysql_native_password plugin that implements native authentication; that is, authentication based on the password hashing method in use from before the introduction of pluggable authentication.
Plugin and Library Names for Native Password Authentication
Plugin or File Plugin or File Name
Server-side plugin mysql_native_password
Client-side plugin mysql_native_password
Library file None (plugins are built in)
Server status variable
Aborted_clients
The number of connections that were aborted because the client died without closing the connection properly. SeeSection C.5.2.11 “Communication Errors and Aborted Connections”. mysql> show status like 'aborted%'; \+------------------+-------+ | Variable_name | Value | \+------------------+-------+ | Aborted_clients | 1 | | Aborted_connects | 11 | \+------------------+-------+ 2 rows in set (0.00 sec)
Server status variable
Aborted_connects
The number of failed attempts to connect to the MySQL server. See Section C.5.2.11 “Communication Errors and Aborted Connections”.
For additional connection-related information check the Connection_errors_xxx status variables and thehost_cache table.
mysql> show status like 'aborted%'; \+------------------+-------+ | Variable_name | Value | \+------------------+-------+ | Aborted_clients | 1 | | Aborted_connects | 11 | \+------------------+-------+ 2 rows in set (0.00 sec)
Server status variables
Binlog_cache_disk_use
The number of transactions that used the temporary binary log cache but that exceeded the value ofbinlog_cache_size and used a temporary file to store statements from the transaction.
The number of nontransactional statements that caused the binary log transaction cache to be written to disk is tracked separately in the Binlog_stmt_cache_disk_use status variable.
Server status variables
Binlog_cache_use
The number of transactions that used the binary log cache.
Server status variables
Bytes_received
The number of bytes received from all clients.
Program Options
MySQL programs determine which options are given first by examining environment variables, then by
processing option files, and then by checking the command line. Because later options take precedence
over earlier ones, the processing order means that environment variables have the lowest precedence and
command-line options the highest.
For the server, one exception applies: The mysqld-auto.cnf option file in the data directory is
processed last, so it takes precedence even over command-line options.
You can take advantage of the way that MySQL programs process options by specifying default option
values for a program in an option file. That enables you to avoid typing them each time you run the
program while enabling you to override the defaults if necessary by using command-line options.
Options are processed in order, so if an option is specified multiple times, the last occurrence takes
precedence. The following command causes mysql to connect to the server running on localhost:
mysql -h example.com -h localhost
There is one exception: For mysqld, the first instance of the –user option is used as a security
precaution, to prevent a user specified in an option file from being overridden on the command line.
Program Options
-? and –help
are the short and long forms of the option that instructs a MySQL program to display its help message.
An option argument begins with one dash or two dashes, depending on whether it is a short form or long
form of the option name. Many options have both short and long forms. For example, -? and –help
are the short and long forms of the option that instructs a MySQL program to display its help message.
You can run the mysql client within the MySQL Server container you just started, and connect it to the MySQL Server. Use the docker exec -it command to start a mysql client inside the Docker container you have started, like the following:
docker exec -it mysql1 mysql -uroot -p
Docker is an increasingly popular software package that creates a container for application development.
There are two versions of Docker – Docker CE (Community Edition) and Docker EE (Enterprise Edition). If you have a small-scale project, or you’re just learning, you will want to use Docker CE.
Install: sudo apt install docker.io Start: sudo systemctl start docker Check: docker --version Grab an mysql docker image: sudo docker pull mysql/mysql-server:5.6.41-1.1.6 Run the image: sudo docker run --name=mysql1 --restart on-failure -d mysql/mysql-server:5.6.41-1.1.6
Once the server is ready, you can run the mysql client within the MySQL Server container you just started, and connect it to the MySQL Server. Use the docker exec -it command to start a mysql client inside the Docker container you have started:
docker exec -it mysql1 mysql -uroot -p
MyISAM
MyISAM stands for Indexed Sequential Access Method. It was the default storage engine for MySQL until December 2009. With the release of MySQL 5.5, MyISAM was replaced with InnoDB.
MyISAM is based on an ISAM algorithm that displays information from large data sets fast. It has a small data footprint and is best suitable for data warehousing and web applications.
Storage Engine Type
There are two types of storage engines, depending on the rollback method:
Non-transactional – write options need to be rolled back manually.
Transactional – write options roll back automatically if they don’t complete.
Summary: MyISAM is a non-transactional, while InnoDB is a transactional type of storage engine.
InnoDB
InnoDB has been the default storage engine for MySQL since the release of MySQL 5.5. It is best suited for large databases that hold relational data.
InnoDB focuses on high reliability and performance, making it great for content management systems. The InnoDB storage engine adheres closely to the ACID model so that data is not corrupted and results are not distorted by exceptional conditions such as software crashes and hardware malfunctions.
Storage Engine Type
There are two types of storage engines, depending on the rollback method:
Non-transactional – write options need to be rolled back manually.
Transactional – write options roll back automatically if they don’t complete.
Summary: MyISAM is a non-transactional, while InnoDB is a transactional type of storage engine.
Binary log options
Binary logging captures changes between backups and is enabled by default.
It’s default setting is –log_bin=binlog
You can change this from the default if needed
Use the –log-bin option to specify a different target location for the binary log.
–log-bin[=base_name]
Command-Line Format –log-bin=file_name
Type File name
Specifies the base name to use for binary log files. With binary logging enabled, the server logs all statements that change data to the binary log, which is used for backup and replication. The binary log is a sequence of files with a base name and numeric extension. The –log-bin option value is the base name for the log sequence. The server creates binary log files in sequence by adding a numeric suffix to the base name.
NOTE: the below command just shows that binary logging is turned on mysql> show variables like 'log_bin'; \+---------------+-------+ | Variable_name | Value | \+---------------+-------+ | log_bin | ON | \+---------------+-------+ 1 row in set (0.01 sec)
Below on the os server you can see the default name ‘binlog’ was used when starting the mysql server:
cd /var/lib/mysql
[root@vmrac1 mysql]# ls -l
-rw-r—–. 1 mysql mysql 154923 Jul 26 16:35 binlog.000001
-rw-r—–. 1 mysql mysql 179 Jul 26 16:36 binlog.000002
-rw-r—–. 1 mysql mysql 59293450 Jul 28 05:58 binlog.000003
-rw-r—–. 1 mysql mysql 125114030 Jul 28 12:21 binlog.000004
-rw-r—–. 1 mysql mysql 179 Jul 28 17:18 binlog.000005
-rw-r—–. 1 mysql mysql 179 Jul 28 17:56 binlog.000006
-rw-r—–. 1 mysql mysql 179 Jul 28 18:01 binlog.000007
-rw-r—–. 1 mysql mysql 14227 Jul 31 11:24 binlog.000008
-rw-r—–. 1 mysql mysql 128 Jul 28 18:11 binlog.index
Here is the list of the important MySQL commands, which you will use time to time to work with MySQL database −
USE Databasename − This will be used to select a database in the MySQL workarea.
SHOW DATABASES − Lists out the databases that are accessible by the MySQL DBMS.
SHOW TABLES − Shows the tables in the database once a database has been selected with the use command.
SHOW COLUMNS FROM tablename: Shows the attributes, types of attributes, key information, whether NULL is permitted, defaults, and other information for a table.
SHOW INDEX FROM tablename − Presents the details of all indexes on the table, including the PRIMARY KEY.
SHOW TABLE STATUS LIKE tablename\G − Reports details of the MySQL DBMS performance and statistics.
mysql> show table status like 'customers' \G *************************** 1. row *************************** Name: customers Engine: InnoDB Version: 10 Row_format: Dynamic Rows: 122 Avg_row_length: 134 Data_length: 16384 Max_data_length: 0 Index_length: 16384 Data_free: 0 Auto_increment: NULL Create_time: 2021-07-26 16:00:54 Update_time: NULL Check_time: NULL Collation: latin1_swedish_ci Checksum: NULL Create_options: Comment: 1 row in set (0.00 sec)
mysql> show columns from limbs;
+——-+————-+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+——-+————-+——+—–+———+——-+
| thing | varchar(20) | YES | | NULL | |
| legs | int | YES | | NULL | |
| arms | int | YES | | NULL | |
+——-+————-+——+—–+———+——-+
3 rows in set (0.00 sec)
Basically mySQL stores data in files in your hard disk. It stores the files in a specific directory that has the system variable “datadir”. Opening a mysql console and running the following command will tell you exactly where the folder is located.
SHOW VARIABLES LIKE ‘datadir’;
mysql> SHOW VARIABLES LIKE 'datadir'; \+---------------+-----------------+ | Variable_name | Value | \+---------------+-----------------+ | datadir | /var/lib/mysql/ | \+---------------+-----------------+ 1 row in set (0.01 sec)
The directory contains folders and some configuration files. Each folder represents a mysql database and contains files with data for that specific database