通过yum安装mysql在本机centos:

--------------------------------------------------

yum install mysql mysql-server php-mysql -y

chkconfig mysqld on

service mysqld start

/usr/bin/mysqladmin -u root password 'NewPassword'

/usr/bin/mysql -u root -p 

--------------------------------------------------


groupadd mysql

useradd -r -g mysql mysql

mv mysql-5.5.27-linux2.6-i686/ /usr/local/

ln -s mysql-5.5.27-linux2.6-i686/ mysql

cd /usr/local/mysql

chown -R mysql .

chgrp -R mysql .

/usr/local/mysql/scripts/mysql_install_db --user=mysql


ERROR:

scripts/mysql_install_db: ./bin/my_print_defaults: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

Neither host 'host-1' nor 'localhost' could be looked up with

./bin/resolveip

Please configure the 'hostname' command to return a correct

hostname.

If you want to solve this at a later stage, restart this script

with the --force option



yum install glibc.i686

yum install zlib.i686

yum install libgcc.i686

#与mysql的版本对应,下载libaio-0.3.107-10.el6.i686.rpm安装

rpm -ivh libaio-0.3.107-10.el6.i686.rpm 


chown -R root:root ./

chown -R mysql:mysql data


cp support-files/mysql.server /etc/init.d/mysql

service mysql start

ps -ef|grep mysql 


#修改mysql的root用户密码,root初始密码为空的:

执行命令:./bin/mysqladmin -u root password '密码'


# 'Can't connect to local MySQL server through socket '/tmp/mysql.sock'

# find / -name mysql.sock

# /var/lib/mysql/mysql.sock,执行以下命令后再重置密码Ok,

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock


Error:

# ./bin/mysql -uroot -p

./bin/mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

安装两个包后解决:

yum install libstdc++.so.6 

yum install libncurses.so.5


设置初始密码:

mysqladmin -u root password 密码

重置密码:

UPDATE mysql.user SET Password = PASSWORD('密码') WHERE User = 'root';

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('密码');

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '密码' WITH GRANT OPTION;

如果本地登录被禁止,还需要从远程登录解决。(localhost/127.0.0.1/% 是有不同含义的,通过localhost连接到mysql是使用UNIX socket,而通过127.0.0.1连接到mysql是使用TCP/IP。)


授权root远程登录

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION

mysql>FLUSH PRIVILEGES


#Mysql初始化root密码和允许远程访问


mysql默认root用户没有密码,输入mysql –u root 进入mysql


1、初始化root密码

进入mysql数据库

mysql>update user set password=PASSWORD('密码') where User='root';


2、允许mysql远程访问,可以使用以下三种方式:


a、改表。

mysql -u root –p

mysql>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;


b、授权。

例如,你想root使用123456从任何主机连接到mysql服务器。

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;

如果你想允许用户jack从ip为10.10.50.127的主机连接到mysql服务器,并使用654321作为密码

mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION;

mysql>FLUSH RIVILEGES


c:在安装mysql的机器上运行:

//进入MySQL服务器

d:\mysql\bin\>mysql -h localhost -u root

//赋予任何主机访问数据的权限

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;

//使修改生效

mysql>FLUSH PRIVILEGES

//退出MySQL服务器

mysql>EXIT



###mysql管理UI,myadmin

下载解压到apache目录,

使用httpd,目录/var/www/html/myadmin,修改libraries下的config.default.php,参考:

110c110

< $cfg['Servers'][$i]['host'] = '1.1.17.81';

---

> $cfg['Servers'][$i]['host'] = 'localhost';

117c117

< $cfg['Servers'][$i]['port'] = '3306';

---

> $cfg['Servers'][$i]['port'] = '';

124c124

< $cfg['Servers'][$i]['socket'] = '/tmp/mysql.sock';

---

> $cfg['Servers'][$i]['socket'] = '';

215c215

< $cfg['Servers'][$i]['password'] = '密码';

---

> $cfg['Servers'][$i]['password'] = '';