Difference between revisions of "MySQL"
| (14 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
* [https://medium.com/@alef.duarte/cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-155d580f3a06 Medium article] on how to clean out existing installation before reinstalling | * [https://medium.com/@alef.duarte/cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-155d580f3a06 Medium article] on how to clean out existing installation before reinstalling | ||
| + | * Excellent article on [https://www.universalclass.com/articles/computers/mysql-administration-managing-users-and-privileges.htm users and privileges] | ||
| + | * How to reset root MySQL/MariaDB password on Ubuntu 20.04 from [https://help.mikrotik.com/docs/display/ROS/Bonding linuxconfig.org] | ||
| + | * Good instructions for installation on [https://phoenixnap.com/kb/how-to-install-mysql-on-ubuntu-18-04 Ubuntu] | ||
===Resetting the 'root' password=== | ===Resetting the 'root' password=== | ||
| Line 9: | Line 12: | ||
2. Stop the MySQL server. (No instructions here, so I'm going with <code>systemctl stop mysql</code>. No need for sudo since I'm already root.) | 2. Stop the MySQL server. (No instructions here, so I'm going with <code>systemctl stop mysql</code>. No need for sudo since I'm already root.) | ||
| − | 3. | + | 3. Doesn't work. Still getting bounced w/ root password. |
| + | 4. Finally got it to work. In the course of running <code>mysql_secure_installation</code> (which the MySQL installation documentation fails to mention), you will be prompted to enter a root password. | ||
| + | |||
| + | To add a new, non-root user, type: | ||
| + | CREATE USER 'database_user'@'localhost' IDENTIFIED BY 'user_password'; | ||
| + | |||
| + | ===Uninstalling=== | ||
| + | $ sudo apt-get remove --purge mysql-server mysql-client mysql-common -y. | ||
| + | $ sudo apt-get autoremove -y. | ||
| + | $ sudo apt-get autoclean. | ||
| + | rm -rf /etc/mysql. | ||
| + | sudo find / -iname 'mysql*' -exec rm -rf {} \; | ||
| + | |||
| + | ===Percona Server=== | ||
| + | sudo apt-get install gnupg2 | ||
| + | # curl must be installed | ||
| + | wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb | ||
| + | sudo dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb | ||
| + | sudo percona-release setup ps80 | ||
| + | sudo apt-get install percona-server-server | ||
| + | mysql_secure_install | ||
| + | |||
| + | ;Uninstalling | ||
| + | *First, stop the mysql service: <code>sudo systemctl stop mysql</code> | ||
| + | *Next, remove Percona Server for MySQL: <code>sudo apt-get remove percona-server*</code> | ||
| + | * Last, remove the components, which may or may not be installed | ||
| + | $ #Remove Percona XtraBackup | ||
| + | $ sudo apt-get remove percona-xtrabackup-80 | ||
| + | $ #Remove Percona Toolkit | ||
| + | $ sudo apt-get remove percona-toolkit | ||
| + | $ #Remove Orchestrator | ||
| + | $ sudo apt-get remove percona-orchestrator* | ||
| + | $ #Remove MySQL Shell | ||
| + | $ sudo apt-get remove percona-mysql-shell | ||
| + | $ #Remove ProxySQL | ||
| + | $ sudo apt-get remove proxysql2 | ||
| + | $ #Remove MySQL Router | ||
| + | $ sudo apt-get remove percona-mysql-router | ||
| + | Finally, clean out <code>/etc/apt/sources.list.d/</code>. | ||
| + | |||
| + | ===MariaDB=== | ||
| + | $ sudo apt install mariadb-server | ||
| + | $ sudo systemctl status mariadb # p24 this doesn't work, possibly because default 20.04 version is 10.3 | ||
| + | From the MariaDB website: | ||
| + | sudo apt-get install software-properties-common | ||
| + | sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' | ||
| + | sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.dotsrc.org/mariadb/repo/10.5/ubuntu focal main' | ||
| + | |||
| + | Even after thoroughly uninstalling it 3 times, running <code>mysql_secure_installation</code> still thinks I have a (database) root password. I fixed it like this: | ||
| + | sudo mysqladmin --user=root password 'mynewpasswd' | ||
| + | |||
| + | ===Docker=== | ||
Abandoning this. Going to try and run mysql in a docker container. [https://docs.docker.com/engine/install/ubuntu/#install-from-a-package Here] are the docker installation instructions. And now back to our program on [https://dev.mysql.com/doc/refman/8.0/en/linux-installation-docker.html dev.mysql.com] | Abandoning this. Going to try and run mysql in a docker container. [https://docs.docker.com/engine/install/ubuntu/#install-from-a-package Here] are the docker installation instructions. And now back to our program on [https://dev.mysql.com/doc/refman/8.0/en/linux-installation-docker.html dev.mysql.com] | ||
| + | |||
| + | Pull in the latest or specified (8.0) mysql image: | ||
| + | docker pull mysql/mysql-server | ||
| + | This results in: | ||
| + | bch@redbox:~$ sudo docker pull mysql/mysql-server:8.0 | ||
| + | [sudo] password for bch: | ||
| + | 8.0: Pulling from mysql/mysql-server | ||
| + | 501550cfd5c0: Pull complete | ||
| + | e0509d775110: Pull complete | ||
| + | d5a01765d011: Pull complete | ||
| + | 970507e942eb: Pull complete | ||
| + | Digest: sha256:0bb21c0f1aa9296e7deafacec5703b80e4d923dfdfcaa2efbe0c8377a8592128 | ||
| + | Status: Downloaded newer image for mysql/mysql-server:8.0 | ||
| + | docker.io/mysql/mysql-server:8.0 | ||
Latest revision as of 00:50, 23 February 2021
- Medium article on how to clean out existing installation before reinstalling
- Excellent article on users and privileges
- How to reset root MySQL/MariaDB password on Ubuntu 20.04 from linuxconfig.org
- Good instructions for installation on Ubuntu
Resetting the 'root' password[edit]
This is one of the most vexing actions to execute in all of computing administration. It's unclear if what appears to be just plain wrong advice (issue mysqladmin -u root -p flush-privileges password 'new_passwd') is installation, platform or sequence dependent, or if it's just plain wrong. I will catalog below the methods that affirmatively DO NOT WORK to save others the trouble.
- From the MySQL 8.0 Reference Manual
1. "Log on to your system as the Unix user that the MySQL server runs as (for example, mysql)." (This means root, since I've never logged in otherwise.)
2. Stop the MySQL server. (No instructions here, so I'm going with systemctl stop mysql. No need for sudo since I'm already root.)
3. Doesn't work. Still getting bounced w/ root password.
4. Finally got it to work. In the course of running mysql_secure_installation (which the MySQL installation documentation fails to mention), you will be prompted to enter a root password.
To add a new, non-root user, type:
CREATE USER 'database_user'@'localhost' IDENTIFIED BY 'user_password';
Uninstalling[edit]
$ sudo apt-get remove --purge mysql-server mysql-client mysql-common -y.
$ sudo apt-get autoremove -y.
$ sudo apt-get autoclean.
rm -rf /etc/mysql.
sudo find / -iname 'mysql*' -exec rm -rf {} \;
Percona Server[edit]
sudo apt-get install gnupg2 # curl must be installed wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb sudo dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb sudo percona-release setup ps80 sudo apt-get install percona-server-server mysql_secure_install
- Uninstalling
- First, stop the mysql service:
sudo systemctl stop mysql - Next, remove Percona Server for MySQL:
sudo apt-get remove percona-server* - Last, remove the components, which may or may not be installed
$ #Remove Percona XtraBackup $ sudo apt-get remove percona-xtrabackup-80 $ #Remove Percona Toolkit $ sudo apt-get remove percona-toolkit $ #Remove Orchestrator $ sudo apt-get remove percona-orchestrator* $ #Remove MySQL Shell $ sudo apt-get remove percona-mysql-shell $ #Remove ProxySQL $ sudo apt-get remove proxysql2 $ #Remove MySQL Router $ sudo apt-get remove percona-mysql-router
Finally, clean out /etc/apt/sources.list.d/.
MariaDB[edit]
$ sudo apt install mariadb-server $ sudo systemctl status mariadb # p24 this doesn't work, possibly because default 20.04 version is 10.3
From the MariaDB website:
sudo apt-get install software-properties-common sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirrors.dotsrc.org/mariadb/repo/10.5/ubuntu focal main'
Even after thoroughly uninstalling it 3 times, running mysql_secure_installation still thinks I have a (database) root password. I fixed it like this:
sudo mysqladmin --user=root password 'mynewpasswd'
Docker[edit]
Abandoning this. Going to try and run mysql in a docker container. Here are the docker installation instructions. And now back to our program on dev.mysql.com
Pull in the latest or specified (8.0) mysql image:
docker pull mysql/mysql-server
This results in:
bch@redbox:~$ sudo docker pull mysql/mysql-server:8.0 [sudo] password for bch: 8.0: Pulling from mysql/mysql-server 501550cfd5c0: Pull complete e0509d775110: Pull complete d5a01765d011: Pull complete 970507e942eb: Pull complete Digest: sha256:0bb21c0f1aa9296e7deafacec5703b80e4d923dfdfcaa2efbe0c8377a8592128 Status: Downloaded newer image for mysql/mysql-server:8.0 docker.io/mysql/mysql-server:8.0