美文网首页
mySQL数据库安装

mySQL数据库安装

作者: 云养江停 | 来源:发表于2022-01-26 21:00 被阅读0次
#安装
dnflocal install mariadb mariadb-server mariadb-devel
#开启防火墙端口
firewall-cmd --add-port=3306/tcp --permanent
#端口生效
firewall-cmd --reload
#修改配置文件
vim /etc/my.cnf.d/mariadb-server.cnf 
#datadir=/var/lib/mysql修改为datadir=/home/.mysql
[mysqld]
datadir=/home/.mysql
#启动,但启动失败
systemctl restart mariadb.service 
#修改权限
mkdir /home/.mysql/
chown -R mysql:mysql /home/.mysql/
#重新启动
systemctl restart mariadb.service 

#让数据库更安全
[root@MiWiFi-R3P-srv ~] mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
mysql -hlocalhost -uroot -p密码
mysql -hlocalhost -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.3.27-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> GRANT ALL ON *.* TO 'train'@'%'
    -> IDENTIFIED BY '123456'
    -> ;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> GRANT SELECT ON *.* TO 'passa'@'%' IDENTIFIED BY '123456'
    -> ;
Query OK, 0 rows affected (0.000 sec)
开机自启动服务
systemctl  enable  mariadb.service
[root@MiWiFi-R3P-srv ~]# mysql -utrain -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 20

Server version: 10.3.27-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE chenlianful
    -> ;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> Ctrl-C -- exit!

MariaDB [(none)]> SHOW DATABASES
    -> ;
+--------------------+
| Database           |
+--------------------+
| chenlianful        |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.001 sec)

[root@MiWiFi-R3P-srv ~]# #远程登录
[root@MiWiFi-R3P-srv ~]# mysql -h<ifconfig> -u<username> -p<passwd>

相关文章

网友评论

      本文标题:mySQL数据库安装

      本文链接:https://www.haomeiwen.com/subject/adtohrtx.html