数据库开启
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ ## 系统能识别 能用systemctl命令开启
systemctl daemon-reload //数据库重新加载
systemctl start mysqld ## 其他如自启动关闭查看状态跟其他服务命令一个格式
netstat -anpt | grep 3306 ## 开启后查看服务
设置密码
mysqladmin -u root -p password
[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.
5. 允许远程终端连接数据
###########################测试数据库###########################
## 报错
[root@localhost mysql]# mysqladmin -u root -p password//设置数据库的密码 方法二:mysql -u root -p password “123”
Enter password:
ERROR 2002(HY000): Can't connect to local MySQL server through socket '/usr/local/mysq/mysql.sock' (2)
改用
[root@localhost mysql]# mysql -uroot -h 127.0.0.1-p //需要输入数据库服务器的ip地址
#########################允许远程终端连接数据库###########################
[root@localhost mysql]# mysql -uroot -h 127.0.0.1-p
mysql> grant all privileges on *.* to 'root'@'%' identified by '123' with grant option;//允许远程终端连接数据库
Query OK,0 rows affected,1 warning (0.01 sec)
mysql> quit