sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES //支持模块 [root@localhost mysql-5.7.17]# chown mysql:mysql /etc/my.cnf //修改文件属主属组 [root@localhost mysql-5.7.17]# 9.将mysql相关命令添加本地环境配置中 [root@localhost mysql-5.7.17]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile //将MySQL写到本地环境配置中 [root@localhost mysql-5.7.17]# echo 'export PATH' >> /etc/profile //设置全局环境配置 [root@localhost mysql-5.7.17]# source /etc/profile //重新加载配置文件 [root@localhost mysql-5.7.17]# 10.初始化数据库 [root@localhost mysql-5.7.17]# cd /usr/local/mysql/ [root@localhost mysql]# bin/mysqld / > --initialize-insecure / //初始化 > --user=mysql / //用户 > --basedir=/usr/local/mysql / //安装目录 > --datadir=/usr/local/mysql/data //数据库数据文件目录 11.将MySQL服务配置文件复制到/usr/lib/systemd/system/下便于使用systemctl管理 [root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /lib/systemd/system/ //复制 [root@localhost mysql]# systemctl daemon-reload //重新加载 [root@localhost mysql]# systemctl start mysqld.service //启动服务 [root@localhost mysql]# netstat -ntap | grep 3306 //查看tcp3306端口 tcp6 0 0 :::3306 :::* LISTEN 78684/mysqld [root@localhost mysql]# systemctl enable mysqld.service //设置开机自启 Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service. [root@localhost mysql]# 12.配置MySQL密码 [root@localhost mysql]# mysqladmin -u root -p password Enter password: New password: Confirm new password: Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. [root@localhost mysql]# 13.尝试登陆MySQL数据库 [root@localhost mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or /g. Your MySQL connection id is 4 Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
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> grant all privileges on *.* to 'root'@'%' identified by 'abc123' with grant option; //提权让所有终端能够远程登录 Query OK, 0 rows affected, 1 warning (0.00 sec)
15.进入数据库查看所有database [root@localhost mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or /g. Your MySQL connection id is 6 Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
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 databases; //查看数据库 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)