环境:CentOS 6.5 64bit
一、查看系统中是否已经安装mysqld(mysql-server)
[root@szdev03 ~]# rpm -qi mysql-server
package mysql-server is not installed
二、使用yum命令进行mysqld(mysql-server)安装
[root@szdev03 ~]# yum install mysql-server
三、安装成功后,可通过如下命令查看安装的mysqld版本信息
[root@szdev03 ~]# rpm -qi mysql-server
Name : mysql-server Relocations: (not relocatable)
Version : 5.1.73 Vendor: CentOS
Release : 8.el6_8 Build Date: Fri 27 Jan 2017 06:25:43 AM CST
Install Date: Mon 05 Feb 2018 06:41:48 PM CST Build Host: c1bm.rdu2.centos.org
Group : Applications/Databases Source RPM: mysql-5.1.73-8.el6_8.src.rpm
Size : 25884131 License: GPLv2 with exceptions
Signature : RSA/SHA1, Fri 27 Jan 2017 06:35:28 AM CST, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://www.mysql.com
Summary : The MySQL server and related files
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MySQL server and some accompanying files and directories.
三、启动mysql-server服务
使用root权限,执行:
- /etc/init.d/mysqld start
- service mysqld start
[root@szdev03 ~]# /etc/init.d/mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
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 szdev03.xxxxx.com 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.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ]
上面提示需要进行:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h szdev03.xxxxx.com password 'new-password'
以下命令设置成功:
[root@szdev03 ~]# /usr/bin/mysqladmin -u root password 'xxxxxxx'
以下命令设置失败:
[root@szdev03 ~]# /usr/bin/mysqladmin -u root -h szdev03.xxxxx.com password 'xxxxxxx'
/usr/bin/mysqladmin: connect to server at 'szdev03.xxxxx.com' failed
error: 'Lost connection to MySQL server at 'reading initial communication packet', system error: 110
'
四、mysql登陆使用
开启mysql-server后,在普通账号下,登陆mysql成功:
[dup@szdev03 ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution
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>
不过在root账户下,登陆mysql会有如下提示错误:
[root@szdev03 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解决方法如下:
[root@szdev03 ~]# /etc/init.d/mysqld stop
Stopping mysqld: [ OK ]
[root@szdev03 ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@szdev03 ~]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 Source distribution
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> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 3 Changed: 2 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
重启mysql-server:
[root@szdev03 ~]# /etc/init.d/mysqld restart
root账户登陆mysql成功:
[root@szdev03 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
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>