Starting MySQL. [确定]
[root@localhost ~]# service mysql stop
Mysqld服务
[root@terminal opt]# service mysqld restart
Shutting down MySQL.. [确定]
Starting MySQL. [确定]
[root@terminal opt]# service mysqld stop
七、修改root密码、设置权限
使用客户端连接mysql并修改root密码,必须修改密码,否则无法使用。
安装mysql5.6成功后,会为root随机生成一个密码,我们首次使用root登陆时需要,需要使用这个密码,然后修改root密码。操作命令可以参考下文红色字体。
[root@localhost mysql]# cat /root/.mysql_secret
# The random password set for the root user at Thu May 12 15:37:53 2016 (local time): nghlklAC
[root@localhost mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.15
Copyright (c) 2000, 2013, 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> select 1;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql> set password=password(\'root\');
Query OK, 0 rows affected (0.00 sec)
mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
设置权限。必须设置权限,否则mysql不允许本机外的其他客户端连接。
mysql> GRANT ALL PRIVILEGES ON *.* TO \'root\'@\'%\' IDENTIFIED BY \'root\' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
附录A、关闭SELinux权限的操作
设置权限。必须设置权限,否则mysql不允许本机外的其他客户端连接。
查看SELinux权限,如果是Enforcing则说明没有关闭权限。
[root@localhost mysql]#
Enforcing
修改/etc/selinux/config文件,将enforcing改为disabled
[root@localhost mysql]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
~
~
~
~
~
~
"/etc/selinux/config" 13L, 457C 已写入
修改这个配置文件后,需要重启linux服务器,才能生效。Disabled代表关闭了selinux。
Last login: Thu May 12 15:17:19 2016 from 192.168.2.130
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# getenforce
Disabled
附录B、还原mysql数据库
利用sql备份脚本
还原前,需要先创建数据库,这样做的目的是可以灵活定义数据库名称。
使用mysql客户端,登录到mysql(mysql -u root -p)。利用create命令创建需要的数据库(例如create database db_name character set =utf8;),利用use命令将当前数据库切换到刚刚创建的数据库上(例如use db_name;),然后利用source命令还原数据库(例如source /opt/xxx/20160513.sql)。其中,db_name为你需要用到的数据库名称。
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 259
Server version: 5.6.15 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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> create database httc character set =utf8;
Query OK, 1 row affected (0.00 sec)
mysql> create database db_name character set =utf8;
Query OK, 1 row affected (0.00 sec)
mysql> use db_name;
Database changed
mysql> source /opt/xxx/20160513.sql
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.46 sec)
Query OK, 0 rows affected (0.00 sec)
。。。。。。
mysql>
附录C、设置mysql不区分数据库表名大小写
查找my.cnf文件,然后在最后一行添加lower_case_table_names = 1,之后重启mysql。
[root@localhost ~]# find / -name my.cnf
/usr/my.cnf
[root@localhost ~]# vim /usr/my.cnf
# For advice on how to change settings please see
#
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names = 1
重启后,在mysql客户端执行查询语句,出现如下结果则代表设置mysql不区分表名大小写成功。
mysql> show variables like "%case%" ;
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
+------------------------+-------+
2 rows in set (0.00 sec)