Installing Percona Server from Repositories
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
yum list | grep percona
yum install Percona-Server-server-57
service mysql start
service mysql status
service mysql stop
service mysql restart
mysql的配置文件是/etc/my.cnf,打开该文件,可以看到mysql的datadir和log文件等的配置信息,如下:
datadir=/var/lib/mysql
log-error=/var/log/mysqld.log
打开/var/log/mysqld.log文件,搜索字符串A temporary password is generated for root@localhost:,可以找到这个随机密码,通常这一行日志在log文件的最初几行,比较容易看到。
使用找到的随机密码登录mysql,
mysql> select user();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.05 sec)
mysql> set global validate_password_mixed_case_count=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_special_char_count=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_dictionary_file | |
| validate_password_length | 3 |
| validate_password_mixed_case_count | 0 |
| validate_password_number_count | 3 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 0 |
+--------------------------------------+-------+
6 rows in set (0.00 sec)
# 编辑配置文件:
vi /etc/my.cnf
# 在文件末尾添加以下内容([mysqld_safe]里):
plugin-load=validate_password.so
validate-password=OFF
# 重启
service mysql restart
这样就可以在服务器本地,用root账号登录了,并且可以修改密码,但是我们基本都要在其机器上访问mysql,所有就需要授权,如下:
1、创建用户
#foo表示你要建立的用户名,后面的123表示密码,
#localhost限制在固定地址localhost登陆
CREATE USER foo@‘localhost’ IDENTIFIED BY ‘123’;
2、授权
GRANT privileges ON databasename.tablename TO ‘username’@‘host’
说明: privileges - 用户的操作权限,如SELECT , INSERT , UPDATE 等。如果要授予所的权限则使用 ALL;
databasename - 数据库名,tablename-表名,如果要授予该用户对所有数据库和表的相应操作权限则可用表示, 如.*
例如:
GRANT INSERT,DELETE,UPDATE,SELECT ON test.user TO ‘foo’@‘localhost’;
flush privileges;
GRANT ALL PRIVILEGES ON . TO root@‘192.168.1.100’ IDENTIFIED BY ‘root用户的密码’ WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON . TO root@’%’ IDENTIFIED BY ‘root用户的密码’ WITH GRANT OPTION;
WITH GRANT OPTION 这个选项表示该用户可以将自己拥有的权限授权给别人。注意:经常有人在创建操作用户的时候不指定WITH GRANT OPTION选项导致后来该用户不能使用GRANT命令创建用户或者给其它用户授权。
grant all privileges on *.* to root@'%' identified by "password" with grant option ;
flush privileges;
3、设置与更改用户密码
SET PASSWORD FOR ‘username’@‘host’ = PASSWORD(‘newpassword’)
#如果是当前登陆用户
SET PASSWORD = PASSWORD("newpassword");
#例如:
SET PASSWORD FOR ‘foo’@’%’ = PASSWORD(“123456”);
update mysql.user set password=password(‘新密码’) where User=“phplamp” and Host=“localhost”;