MySQL установка и настройка на Ubuntu

Установка MySQL клиента на Ubuntu

sudo apt install mysql-client


Установка MySQL Server на Ubuntu

sudo apt-get install mysql-server

Узнать версию MySQL Server

mysqld —version

или

mysqladmin —version

Вывод

/usr/sbin/mysqld Ver 8.0.32-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))


Проверяем состояние сервера на Ubuntu

sudo service mysql status

Вывод

mysql.service — MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2023-03-02 22:51:55 MSK; 11min ago
Process: 11471 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 11480 (mysqld)
Status: «Server is operational»
Tasks: 39 (limit: 4503)
Memory: 371.2M
CPU: 4.064s
CGroup: /system.slice/mysql.service
└─11480 /usr/sbin/mysqld

мар 02 22:51:47 comp-TM1709 systemd[1]: Stopped MySQL Community Server.
мар 02 22:51:47 comp-TM1709 systemd[1]: mysql.service: Consumed 2.153s CPU time.
мар 02 22:51:47 comp-TM1709 systemd[1]: Starting MySQL Community Server…
мар 02 22:51:55 comp-TM1709 systemd[1]: Started MySQL Community Server.


ss

sudo ss -tap | grep mysql

LISTEN 0 151 127.0.0.1:mysql 0.0.0.0:* users:((«mysqld»,pid=11480,fd=33))
LISTEN 0 70 127.0.0.1:33060 0.0.0.0:* users:((«mysqld»,pid=11480,fd=21))


Проверяем запущен ли сервер MySQL

sudo netstat -tap | grep mysql

Вывод:

tcp 0 0 localhost:mysql 0.0.0.0:* LISTEN 1102/mysqld
tcp 0 0 localhost:33060 0.0.0.0:* LISTEN 1102/mysqld


Если сервер не работает, запускаем команду

sudo service mysql restart


Создаем журнал

sudo journalctl -u mysql

Работаем с mysql

sudo mysql

или

sudo mysql -u root -p

или

mysql -u root -p -h 127.0.0.1 -P 3306


Создаем нового пользователя root на Ubuntu

CREATE USER root@localhost IDENTIFIED BY ‘pas123’;
GRANT ALL ON *.* TO root@localhost WITH GRANT OPTION;

или

ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘pas123’;


Выводим разрядность mysql

show variables like ‘version_compile_machine’;

+————————-+———+
| Variable_name | Value |
+————————-+———+
| version_compile_machine | x86_64 |
+————————-+———+
1 row in set (0,33 sec)


Выйти из mysql

exit


Устанавливаем Workbench на Ubuntu

sudo apt install snapd

snap install mysql-workbench-community

или

sudo apt install mysql-workbench-community

Запускаем Workbench  и правым кликом мыши переходим в Edit Connection

Edit connection

Открывается Manage Server Connection — > Connection -> Parametrs и устанавливаем hostname — localhost, port — 3306, user — root и вводим пароль.

manage server connection

Если появится ошибка на Ubuntu при запуске Workbench

Cannot Connect to Database Server

Your connection attempt failed for user ’root’ to the MySQL server at localhost:3306:

An AppArmor policy prevents this sender from sending this message to this recipient; type=»method_call», sender=»:1.152″ (uid=1000 pid=8985 comm=7snap/mysql-workbench-community/10/usr/bin/- mysql-w» label=»snap.mysql-workbench-community.mysql-workbench- community (enforce)») interface=»org.freedesktop.Secret.Service» member=»OpenSession» error name=»(unset)» requested_reply=»0″ destination=»:1.17″ (uid=1000 pid=1753 comm=7usr/bin/gnome- keyring-daemon -daemonize -login» label=»unconfined”)

Please:

  1. Check that MySQL is running on address localhost

  2. Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)

  3. Check the user root has rights to connect to localhost from your address (MySQL rights define what clients can connect to the server and from which machines)

  4. Make sure you are both providing a password if needed and using the correct password for localhost connecting from the host address you’re connecting from

Cannot Connect to Database Server

или

Store Password
Could not store password: An AppArmor policy prevents this sender
from sending this message to this recipient; type=»method_caU»( sender=»:1.184″ (uid=1000 pid=13106 comm=»/snap/mysql-workbench- community/10/usr/bin/mysql-w» label=»snap.mysql-workbench- community.mysql-workbench-community (enforce)») interface=»org.freedesktop.Secret.Service» member=»OpenSession» error name=»(unset)» requested_reply=»0″ destination=»:- 1.17″ (uid=1000 pid=1753 comm=»/usr/bin/gnome-keyring-daemon-daemonize -login» label=»unconfined»)

 

Could not store password mysql

Устанавливаем на Ubuntu

 

sudo snap connect mysql-workbench-community:password-manager-service :password-manager-service

И ошибки должны пропасть.

Дополнительные команды, если требуются

snap connect mysql-workbench-community:password-manager-service
— snap connect mysql-workbench-community:ssh-keys
— snap connect mysql-workbench-community:cups-control

Переходим в Workbench и запускаем Local instance и вводим пароль, после чего открывается графический интерфейс базы данных

mysql connections

Workbench

 

416

Leave a Reply

Ваш адрес email не будет опубликован.