鲲鹏服务器、ARM架构Ubuntu18.04.3系统安装MySQL并修改数据目录

9 篇文章 0 订阅
  • 第一次用Ubuntu安装MySQL 真是各种坑。。。。
  • Ubuntu系统安装MySQL 修改MySQL默认数据目录/var/lib/mysql
  1. 安装MySQL
apt-get update
apt-get install mysql-server -y
  1. 查看MySQL是否安装成功
#安装好以后默认是启动的
root@test-server02:/opt# systemctl status mysql
· mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2024-08-20 13:55:49 CST; 1min 34s ago
 Main 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>
  1. 修改MySQL配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address           = 127.0.0.1
#注释掉上面的配置、这个不注释根本连不上
max_connections=1000
#放开此参数,修改成1000 这个是研发需求
  1. 修改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 Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2024-08-20 15:07:41 CST; 8s ago
  Process: 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>
  1. 修改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';
#新开一个窗口测试
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值