1、下载安装包
首先查看Linux版本:
[[email protected] ~]# lsb_release -a LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: RedHatEnterpriseServer Description: Red Hat Enterprise Linux Server release 6.3 (Santiago) Release: 6.3 Codename: Santiago
结果显示系统为64位Redhat6.3 ,去Mysql官网(http://dev.mysql.com/downloads/mysql#downloads)下载相应的版本。
wget http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-devel-5.5.36-1.el6.x86_64.rpm
wget http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-client-5.5.36-1.el6.x86_64.rpm
wget http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-server-5.5.36-1.el6.x86_64.rpm
2、安装Mysql服务和客户端
rpm -ivh MySQL-server-5.5.36-1.el6.x86_64.rpm
[[email protected] mysql]# rpm -ivh MySQL-server-5.5.36-1.el6.x86_64.rpm Preparing... ########################################### [100%] 1:MySQL-server ########################################### [100%] PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems at http://bugs.mysql.com/
[[email protected] mysql]# rpm -ivh MySQL-client-5.5.36-1.el6.x86_64.rpm
Preparing… ########################################### [100%]
1:MySQL-client ########################################### [100%]
可能遇到的问题:
1>如果出现类似:
file /usr/share/mysql/charsets/hebrew.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64 file /usr/share/mysql/charsets/hp8.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64 file /usr/share/mysql/charsets/keybcs2.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64 file /usr/share/mysql/charsets/koi8r.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64 file /usr/share/mysql/charsets/koi8u.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64 file /usr/share/mysql/charsets/latin1.xml from install of MySQL-server-5.5.36-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.61-4.el6.x86_64
说明有包冲突,这时候要移除冲突的包,使用命令:
yum -y remove mysql-libs-5.1.61*
2>如果移除时出现:
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager Updating certificate-based repositories. Unable to read consumer identity Existing lock /var/run/yum.pid: another copy is running as pid 14110.
说明YUM正在更新,使用命令:
rm -f /var/run/yum.pid
3、服务启动、停止、重新启动
[[email protected] usr]# service mysql start
[[email protected] usr]# service mysql stop
[[email protected] usr]# service mysql restart
4、修改root密码
[[email protected] bin]# mysqladmin -u root -p’root’ password ‘rockontrol’
5、常见问题
登录出现 Access denied for user ‘root’@’localhost’ (using password:YES)。解决步骤如下:
a:以root用户登录系统
b:看一下Mysql服务的状态 如果启动则杀掉进程 命令如下
[[email protected] ~]# /etc/init.d/mysql status ERROR! MySQL is running but PID file could not be found [[email protected] ~]# ps aux|grep mysql root 1468 0.0 0.0 115216 1680 ? S 6月16 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid mysql 1638 0.0 2.7 1040276 455956 ? Sl 6月16 0:29 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid root 17015 0.0 0.0 112660 976 pts/0 S+ 08:42 0:00 grep --color=auto mysql [[email protected] ~]# kill 1468 [[email protected] ~]# kill 1638 [[email protected] ~]# kill 17015
c:启动特权命令:mysqld_safe –skip-grant-tables &
d:在重新打开一个连接以普通用户命令进去 这时候就不需要在输入密码了
[[email protected] ~]# mysql -u root -p Enter password:
直接回车就可以进去了 然后修改user表的密码就可以了
mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select host,user,password from user; +-----------------------+------+-------------------------------------------+ | host | user | password | +-----------------------+------+-------------------------------------------+ | localhost | root | *68A463BD53874E39A4D68117C03FB1A777EC9DA9 | | localhost.localdomain | root | *68A463BD53874E39A4D68117C03FB1A777EC9DA9 | | 127.0.0.1 | root | *68A463BD53874E39A4D68117C03FB1A777EC9DA9 | | ::1 | root | *68A463BD53874E39A4D68117C03FB1A777EC9DA9 | +-----------------------+------+-------------------------------------------+ 4 rows in set (0.00 sec) mysql> update user set host='%' where host='localhost'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update user set password=''; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0
这样就清空所有的密码了
e:这时候可以退出特权模式 重新启动Mysql服务 然后修改一下密码就可以了
SET PASSWORD=PASSWORD('123456');
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/2744.html