1.新建数据库目录且设置权限:

mkdir mysql
chown -R mysql:mysql /www/mysql

2.设置apparmor

想要禁用AppArmor(跳过步骤2):
(1)sudo systemctl disable apparmor
(2)重新启动系统

vim /etc/apparmor.d/usr.sbin.mysqld

找到:

# Allow data dir access
  /var/lib/mysql/ r,
  /var/lib/mysql/** rwk,

修改:

# Allow data dir access
  /www/mysql/ r,
  /www/mysql/** rwk,

重启apparmor服务:

service apparmor restart

3.再初始化MySQL:

mysqld --initialize-insecure --user=mysql --datadir=/www/mysql

3.启动MySQL:

sudo systemctl start mysql.service

4.远程访问配置:

1. 修改配置/etc/mysql/mysql.conf.d
    [mysqld]
    bind-address = 0.0.0.0
2.mysql> 添加用户
    CREATE USER 'root'@'%' IDENTIFIED BY 'root';
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
3.重启:
    sudo systemctl restart mysql

MySQL启动停止命令:

MySQL 8.0.35
sudo systemctl start mysql.service
sudo systemctl stop mysql.service
sudo systemctl restart mysql.service
sudo systemctl status mysql.service
sudo systemctl enable mysql.service
配置文件: /etc/mysql/mysql.conf.d/mysqld.cnf

MySQL数据库导入导出SQL文件:

1.导出整个数据库(包括数据库中的数据):
mysqldump -u username -p password dbname > dbname.sql;
2.导出数据库中的数据表(包括数据表中的数据):
mysqldump -u username -p password dbname tablename > tablename.sql;
3.导出数据库结构(不包括数据,只有创建数据表语句):
mysqldump -u username -p password -d dbname > dbname.sql;
4.导出数据库中数据表的表结构(不包括数据,只有创建数据表语句):
mysqldump -u username -p password -d dbname tablename > tablename.sql

5.先创建数据库:CREATE DATABASE mydatabase;
mysql -u username -p password database_name < dbname.sql

转:https://www.cnblogs.com/linxiyue/p/8229048.html


fangjunai
5 声望0 粉丝