安装mysql
yum -y install mysql-serveryum -y install mysql mysql-devel都显示完成就可以了
查看mysql的版本号
rpm -qi mysql-server数据库目录
/var/lib/mysql/配置文件/usr/share /mysql(mysql.server命令及配置文件)相关命令/usr/bin(mysqladmin mysqldump等命令)启动脚本/etc/rc.d/init.d/(启动脚本文件mysql的目录)
启动mysql:
service mysqld start
停止mysql:
service mysqld stop
修改密码及配置:
yum 安装的mysql默认有两个用户一个是空用户也就是匿名用户,一个是root但是密码也是为空的,这样可不行。
首先如果你在用匿名用户或者登陆后遇到这个错:Ignoring query to other database
说明你登陆的时候没有加-u这个参数
下面说说怎么配置吧
二、配置
[root@sample ~]# vi /etc/my.cnf ← 编辑MySQL的配置文件[mysqld]
datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Default to using old password format for compatibility with mysql 3.x# clients (those using the mysqlclient10 compatibility package).old_passwords=1 ← 找到这一行,在这一行的下面添加新的规则,让MySQL的默认编码为UTF-8default-character-set = gbk ← 添加这一行然后在配置文件的文尾填加如下语句:[mysql]
default-character-set = gbk三、启动MySQL服务
[root@sample ~]# chkconfig mysqld on ← 设置MySQL服务随系统启动自启动
如果上述命令失败,显示 bash: chkconfig: command not found,见本文最下面解决方法
[root@sample ~]# chkconfig --list mysqld ← 确认MySQL自启动
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 如果2--5为on的状态就OK[root@sample ~]# /etc/rc.d/init.d/mysqld start ← 启动MySQL服务
启动mysql [确定]
备 注:如果这一部执行失败有可能是/var/lib/mysql 没有数据库文件,会报【 Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist】,这是需要执行mysql_install_db命令就OK了。
四、MySQL的root用户设置密码
MySQL在刚刚被安装的时候,它的root用户是没有被设置密码的。首先来设置MySQL的root密码。[root@sample ~]# mysql -u root ← 用root用户登录MySQL服务器
:如果出现错误Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2),
:则查看mysql是否启动 /etc/rc.d/init.d/mysqld status, 没有启动则/etc/rc.d/init.d/mysqld start
mysql> select user,host,password from mysql.user; ← 查看用户信息mysql>set password for root@localhost=password('在这里填入root密码'); ← 设置root密码mysql>set password for root@域名=password('在这里填入root密码');mysql> delete from mysql.user where user=''; ← 删除匿名用户mysql> exit ← 退出MySQL服务器【测试设置的密码是否正确】 五、删除测试用数据库mysql> show databases; ← 查看系统已存在的数据库mysql> drop database test; ← 删除名为test的空数据库六、对MySQL进行测试。包括建立新用户,以及用对关系性数据库进行数据库操作的指令来试着建立数据库及数据表。这里,新建用户以 sleinetpub为例。
[root@sample ~]# mysql -u root -p ← 通过密码用root登录
Enter password: ← 在这里输入密码mysql> grant all privileges on test.* to sleinetpub@localhost identified by '在这里定义密码'; ← 建立对test数据库有完全操作权限的名为sleinetpub的用户
mysql> select user from mysql.user where user='sleinetpub'; ← 确认sleinetpub用户的存在与否mysql> exit ← 退出MySQL服务器[root@sample ~]# mysql -u sleinetpub -p ← 用新建立的sleinetpub用户登录MySQL服务器Enter password: ← 在这里输入密码mysql> create database test; ← 建立名为test的数据库mysql> show databases; ← 查看系统已存在的数据库mysql> use test ← 连接到数据库mysql> create table test(num int, name varchar(50)); ← 在数据库中建立表mysql> show tables; ← 查看数据库中已存在的表mysql> drop table test; ← 删除表mysql> show databases; ← 查看已存在的数据库Empty set (0.01 sec) ← 确认test数据库已被删除(这里非root用户的关系,看不到名为mysql的数据库)mysql> exit ← 退出MySQL服务器 七、删除测试用过的遗留用户[root@sample ~]# mysql -u root -p ← 通过密码用root登录Enter password: ← 在这里输入密码mysql> revoke all privileges on *.* from sleinetpub@localhost; ← 取消sleinetpub用户对数据库的操作权限mysql> delete from mysql.user where user='sleinetpub' and host='localhost'; ← 删除sleinetpub用户mysql> select user from mysql.user where user='sleinetpub'; ← 查找用户sleinetpub,确认已删除与否Empty set (0.01 sec) ← 确认sleinetpub用户已不存在mysql> flush privileges; ← 刷新,使以上操作生效mysql> exit八、最后,重新启动一次HTTP服务。
[root@undefined /]# /etc/rc.d/init.d/mysqld stop ← 停止HTTP服务
停止mysql [确定][root@undefined /]# /etc/rc.d/init.d/mysqld start ← 启动HTTP服务
启动mysql [确定]
各种保存解决方案
First things first. Log in as root and stop the mysql daemon. sudo /etc/init.d/mysql stop Now lets start up the mysql daemon and skip the grant tables which store the passwords.sudo mysqld_safe --skip-grant-tables&(press Ctrl+C now to disown the process and start typing commands again)You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.sudo mysql --user=root mysqlupdate user set Password=PASSWORD('new-password');flush privileges;exit; Now kill your running mysqld then restart it normally. sudo killall mysqld_safe&(press Ctrl+C now to disown the process and start typing commands again)/etc/init.d/mysql startYou should be good to go. Try not to forget your password again. |
It seems to me that a lot of people have auth denial when trying to make connections to MySQL. They seem to ignore the text of the error message. ‘Access Denied’ means access denied, nothing else.
Remember three things have to match. The host as MySQL sees it, the username, and the password. When MySQL returns access denied it’s not broken. One or more of those three things does not match. I don’t really need to reiterate what’s in the . Chang the lock or change the key to make it fit.
主从配置相关:
GRANT ALL ON *.* TO slave_1@'192.168.253.210' IDENTIFIED BY 'slave_1';
CHANGE MASTER TO MASTER_HOST='192.168.253.206',MASTER_USER='slave_1',MASTER_PASSWORD='slave_1',MASTER_LOG_FILE='mysql-bin.000004',MASTER_LOG_POS=788;