8. 配置mysql服务开机自动启动
# cp /home/mysql/support-files/mysql.server /etc/init.d/mysqld
# 拷贝启动文件到/etc/init.d/下并重命令为mysqld
# chmod 755 /etc/init.d/mysqld # 增加执行权限
# chkconfig --list mysqld # 检查自启动项列表中没有mysqld这个,
# chkconfig --add mysqld # 如果没有就添加mysqld:
# chkconfig mysqld on # 用这个命令设置开机启动:
9. mysql服务启动/重启/停止
# service mysqld start # 启动服务
# service mysqld restart # 重启服务
# service mysqld stop # 停止服务
10. 初始化mysql用户root的密码
# cd /home/mysql
# ./bin/mysqladmin -u root -p '**mjT,#x_5sW' password '123456' mysqladmin: # 刚刚之前的初始密码
[Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysql> use mysql
Database changed
mysql> update user set authentication_string = PASSWORD('123456') where user = 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 1
mysql> \s
--------------
mysql Ver 14.14 Distrib 5.7.13, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 3
Current database: mysql
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.13 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 1 hour 29 min 17 sec
Threads: 1 Questions: 50 Slow queries: 0 Opens: 136 Flush tables: 1 Open tables: 129 Queries per second avg: 0.009
--------------
可能会出现密码错误登陆不进去的情况:
1)使用service mysqld stop停止服务,然后使用./home/mysql/bin/mysqld_safe --skip-grant-tables &启动mysql服务,
2)输入 ./home/mysql/bin/mysql -u root -p 回车进入
>use mysql;
update mysql.user set authentication_string=password('123456') where user='root';
> flush privileges; 更新权限
> quit 退出
11. mysql远程授权
重新启动mysql服务,使用修改后的密码登陆,有可能进去mysql后提示ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.需要执行下
SET PASSWORD = PASSWORD('123456');问题解决
[root@testfornss ~]# mysql -u root -p
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
grant all on *.* to 'root'@'%' identified by '123456';
参考博文:http://www.cnblogs.com/gaojupeng/p/5727069.html
http://blog.csdn.net/zl17/article/details/8589454