本文主要是介绍鲲鹏服务器、ARM架构Ubuntu18.04.3系统安装MySQL并修改数据目录,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- 第一次用Ubuntu安装MySQL 真是各种坑。。。。
- Ubuntu系统安装MySQL 修改MySQL默认数据目录/var/lib/mysql
- 安装MySQL
apt-get update
apt-get install mysql-server -y
- 查看MySQL是否安装成功
#安装好以后默认是启动的
root@test-server02:/opt# systemctl status mysql
· mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)Active: active (running) since Tue 2024-08-20 13:55:49 CST; 1min 34s agoMain PID: 10728 (mysqld)Tasks: 27 (limit: 4915)CGroup: /system.slice/mysql.service└─10728 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
Aug 20 13:55:49 sdgs-server02 systemd[1]: Starting MySQL Community Server...
Aug 20 13:55:49 sdgs-server02 systemd[1]: Started MySQL Community Server.
#登录以后默认没有密码 这个就很坑 还以为和centos一样设置密码就行
root@test-server02:/opt# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.42-0ubuntu0.18.04.1 (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>
- 修改MySQL配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 127.0.0.1
#注释掉上面的配置、这个不注释根本连不上
max_connections=1000
#放开此参数,修改成1000 这个是研发需求
- 修改MySQL数据目录
#停掉MySQL
systemctl stop mysql
#移动MySQL默认数据目录:/var/lib/mysql
root@test-server02:~# cd /var/lib/
root@test-server02:/var/lib# mv mysql /opt/
#修改MySQL配置
vim /etc/mysql/mysql.conf.d/mysqld.cnf
datadir = /opt/mysql
#修改上面配置
#授予权限
chown -R mysql.mysql /opt/mysql
修改apparmor配置
vim /etc/apparmor.d/usr.sbin.mysqld# Allow data dir access/opt/mysql/ r,/opt/mysql/** rwk,
#找到上面这两处进行修改#重启apparmor服务
systemctl restart apparmor
#启动MySQL
root@test-server02:/opt/mysql# systemctl restart mysql
root@test-server02:/opt/mysql# systemctl status mysql
· mysql.service - MySQL Community ServerLoaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)Active: active (running) since Tue 2024-08-20 15:07:41 CST; 8s agoProcess: 26099 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)Process: 26080 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)Main PID: 26101 (mysqld)Tasks: 27 (limit: 4915)CGroup: /system.slice/mysql.service└─26101 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
Aug 20 15:07:41 sdgs-server02 systemd[1]: Starting MySQL Community Server...
Aug 20 15:07:41 sdgs-server02 systemd[1]: Started MySQL Community Server.
root@sdgs-server02:/opt/mysql# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.42-0ubuntu0.18.04.1 (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> SHOW VARIABLES LIKE 'datadir';
+---------------+-------------+
| Variable_name | Value |
+---------------+-------------+
| datadir | /opt/mysql/ |
+---------------+-------------+
1 row in set (0.00 sec)
mysql>
- 修改MySQL密码&&赋予远程访问权限
这一块是最坑的,由于第一次安装不知道,修改密码的时候直接使用mysql命令即可、不要用mysql -uroot、这样改了以后不生效、更不要听网上的删掉root用户然后重新建更不行
root@test-server02:~# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.42-0ubuntu0.18.04.1 (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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'sdgs123456';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'sdgs123456';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@localhost IDENTIFIED BY 'sdgs123456';
#新开一个窗口测试
这篇关于鲲鹏服务器、ARM架构Ubuntu18.04.3系统安装MySQL并修改数据目录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!