卸载mysql
yum remove mysql
使用yum安装MySQL(CentOS 6.2):
第一次先安装repository
mkdir /home/tools
mkdir /home/tools/mysql
cd /home/tools/mysql
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
//wget http://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
sudo yum localinstall
mysql57-community-release-el7-11.noarch.rpm
sudo yum install mysql-community-server
4、启动
4.1、启动服务:
service mysqld start
4.2、开机启动
chkconfig --levels 235 mysqld on
5、配置
在/etc/my.cnf中添加
validate-password=OFF
不然简单密码将不能被mysql接受
5.1、MySQL安全安装
执行下面的命令:
/usr/bin/mysql_secure_installation
涉及内容包括:
设置或更改root密码 ( 初次安装,初始密码:grep 'temporary password' /var/log/mysqld.log)
移除匿名用户
禁止远程登录root
删除测试数据库test
重新加载授权表
******** 完成上面的步骤,即成功完成安装
常见异常
Mysql:is not allowed to connect to this MySQL server
如果你想连接你的mysql的时候发生这个错误:
ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL server 解决方法: 1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"mysql -u root -pvmware
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
//刷新系统权限表
mysql>flush privileges;mysql>select host, user from user;
2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。 GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码 GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123ABCabc' WITH GRANT OPTION;
重置密码方法
可尝试这样启动 mysqld_safe -skip-grant-tables
或者
在/etc/my.ini的[mysqld]字段加入:skip-grant-tables重启mysql服务,这时的mysql不需要密码即可登录数据库然后进入mysqlmysql>use mysql;mysql>update user set password=password('新密码') WHERE User='root';mysql>flush privileges;运行之后最后去掉my.ini中的skip-grant-tables,重启mysqld即可。
5.7 中用:update user set authentication_string=password('123ABCabc') WHERE User='root';
ALTER USER USER() IDENTIFIED BY password('123ABCabc');
You must reset your password using ALTER USER statement before executing this statement
通过"skip-grant-tables"配置,客户端连接 ,修改 user 表的字段 password_expired 为 'N';
6、自定义MySQL数据文件目录
有时需要自定义MySQL的数据文件夹,即datadir;
6.1、建立目标目录,这里假定为 /home/data/mysql;
service mysqld stop
mkdir /home/data
mv /var/lib/mysql /home/data/
mkdir /home/data/mysql/log/
touch mysqld.log
6.2、授权目录读写权限给MySQL的运行用户,上面安装后的MySQL会以用户mysql运行,则授权语句如下:
chown -R mysql:mysql /home/data/mysql
6.3、修改/etc/my.cnf文件,[mysqld]增加datadir、socket配置,[client]也需要增加socket配置
[mysqld]
datadir=/home/data/mysql
socket=/home/data/mysql/mysql.sock
[client]
socket=/home/data/mysql/mysql.sock
mysql 5.7配置 示例
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[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 # # 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 port=3307 server_id=1 character-set-server=utf8mb4 datadir=/home/data/mysql socket=/home/data/mysql/mysql.sock validate-password=OFF # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0
log-error=/home/data/mysql/log/mysqld.log pid-file=/home/data/mysql/mysqld.pid [client] socket=/home/data/mysql/mysql.sock
6.4、如果启动失败,可通过cat /var/log/mysqld.log 查看启动日志,如果出现如下错误,则是由于SELINUX限制引起
InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
解决方法: chcon -Rt mysqld_db_t /home/data/mysql
7、
一、Warning: World-writable config file '/etc/my.cnf' is ignored
To fix this problem, use the following command to change file’s permissions
要修改该问题,使用以下命令更改该文件的权限。
chmod 644 /etc/my.cnf
4、找到my.cnf配置文件
如果/etc/目录下没有my.cnf配置文件,请到/usr/share/mysql/下找到*.cnf文件,拷贝其中一个到/etc/并改名为my.cnf)中。命令如下: [root mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf