Note

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

Package:Mysql-community

From Funtoo
Revision as of 00:00, October 24, 2021 by Drobbins (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Mysql-community

   Tip

We welcome improvements to this page. To edit this page, Create a Funtoo account. Then log in and then click here to edit this page. See our editing guidelines to becoming a wiki-editing pro.

   Note

mysql-community is what known as MySQL, version 8. The name mysql-community is just a distinct ebuild name to point a significant changes compared to version 5.x and that mysql-community is an open source version, not enterprise commercial software.

MySQL is the M in the lamp/lemp/llmp stack. It is a popular, & common database that accepts SQL statements. dev-db/mariadb & No results are drop in replacements for MySQL.

Installation

root # emerge mysql-community

First Run

MySQL requires configuration upon instillation.

To deploy MySQL:

root # mysqld --initialize-insecure --default_authentication_plugin=mysql_native_password --datadir=/var/lib/mysql

This will create MySQL base directory, by default /var/lib/mysql as well as an empty password for your initial database setup. This is preliminary step before setting up your password, see below

Init

To start mysql:

root # rc-service mysql start

To start upon boot:

root # rc-update add mysql default

Secure installation

Now, run mysql_secure_installation. You will be promted for setting your password, as well as other required steps.

root # mysql_secure_installation

Usage

To use mysql you will need to run MySQL as the funtoo root user, logging in as the mysql database root user. The system root user is not the same as the database root user, and passwords for both should be different.

root # mysql -u root -p
Enter password: 
mysql>

mysql is now blinking at you ready for SQL statements.

Root use is discouraged, for every database you require, create a user, and a database specific for the application, then allow the user access with as stripped down as possible permissions. We will use oleg examples of creating a oleg user & database.

root # mysql -u root -p
Enter password: 
mysql> CREATE USER 'oleg'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'oleg'@'localhost'
     ->WITH GRANT OPTION;
mysql> \q

Let's login with "oleg" account we created above. And let's try creating a database.

root # mysql -u oleg -p
mysql> CREATE DATABASE betelgeuse;

AutoLogin

   Note

mysql_config_editor is finicky about security and you must have a valid login session for the command to work. Be sure you have used su --login or equivalent, and the command will not work if you simply lxc enter an LXD container as root. Perform a su --login root first.

MySQL Community has a new tool, mysql_config_editor, for storing credentials for auto-login to MySQL. The ~/.mylogin.cnf file is now used for this purpose, which is encrypted on-disk by mysql_config_editor, so you must use this tool to store credentials in this file. To allow auto-login to mysql, use the following command:

root # mysql_config_editor reset
root # mysql_config_editor --user=root --password
Enter password: ********
root # mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25051
Server version: 8.0.26 Gentoo Linux mysql-community-8.0.26

Copyright (c) 2000, 2021, 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> quit
Bye

Logging

By default MySQL logs every action, including leaving plain text passwords in its history file.

To remove the history file:

root # rm /root/.mysql_history

To automatically remove future history:

root # ln -s /dev/null /root/.mysql_history

For further references, please, follow this great guide: https://downloads.mysql.com/docs/refman-8.0-en.pdf