将mysql加入到可控制启动的服务的文件夹内,并命名mysql,即service可控制的服务名,至此可用service mysql start控制启动mysql
/etc/init.d 是/etc/rc.d/init.d的链接,在/etc/init.d添加一个文件会同步在/etc/rc.d/init.d下添加一个相同文件
1
2
[iyunv@bogon liuzhen]# cd /usr/local/mysql/
[iyunv@bogon mysql]# cp support-files/mysql.server /etc/init.d/mysql
开机自启动mysql服务
on : 针对的服务有等级限制,具体查询chkconfig详细
chkconfig mysql on
现在可以使用下面的命令启动mysql
1
[iyunv@bogon liuzhen]# service mysql start
停止mysql服务
1
[iyunv@bogon liuzhen]# service mysql stop
重启mysql服务
1
[iyunv@bogon liuzhen]# service mysql restart
下面两种命令作用相同
systemctl [stop|start|restart] 服务名
service 服务名 [stop|start|restart]
回车在接下来的提示中设置新密码即可。。
1
2
3
4
[iyunv@bogon liuzhen]# mysqladmin -u root password
New password:
Confirm new password:
[iyunv@bogon liuzhen]#
连接到mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@bogon mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.35 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>
mysql>use mysql;
mysql>desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //为root添加远程连接的能力。
mysql>update user set Password = password('xxxxxx') where User='root';
mysql>select Host,User,Password from user where User='root';
mysql>flush privileges; //刷新权限
mysql>exit //退出
以下其余四个GRANT例子
给来自192.168.155.1的用户user1分配可对数据库dbname的tablename表进行SELECT,INSERT,UPDATE,DELETE,CREATE,DROP等操作的权限,并设定密码为123456。
对表操作权限还有好多如ALTER等
mysql>GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON dbname.tablename TO 'user1'@'192.168.155.1' IDENTIFIED BY '123456';
给来自192.168.155.1的用户user2分配可对数据库dbname所有表进行所有操作的权限,并设定口令为123456。
mysql>GRANT ALL PRIVILEGES ON dbname.* TO 'user2'@'192.168.155.1' IDENTIFIED BY '123456';
给来自192.168.155.1的用户user3分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123456。
mysql>GRANT ALL PRIVILEGES ON *.* TO 'user3'@'192.168.155.1' IDENTIFIED BY '123456';
给本机用户user4分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123456。
mysql>GRANT ALL PRIVILEGES ON *.* TO 'user4'@'localhost' IDENTIFIED BY '123456';