Linux系统安装mysql5.5

1.检查系统是否自带安装mysql

[root@localhost ~]# rpm -qa | grep mysql

显示:

mysql-libs-5.1.71-1.el6.x86_64

2.强力卸载mysql

[root@localhost ~]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64

3.安装新版本mysql,先解压

[root@localhost ~]# tar -xvzf mysql-5.5.60-linux-glibc2.12-x86_64.tar.gz

剪切解压后的mysql目录到系统的本地软件目录:

[root@localhost ~]# mv mysql-5.5.60-linux-glibc2.12-x86_64 /usr/local/mysql -f

添加系统mysql组和mysql用户:

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql

修改目录权限:

[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R mysql:mysql ./

创建mysql数据目录,新目录不存在则创建:

[root@localhost mysql]# mkdir -p data

初始化数据库:

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

修改权限为root:

[root@localhost mysql]# chown -R root:root ./
[root@localhost mysql]# chown -R mysql:mysql data

到此数据库安装完毕.

4.启动mysql服务和添加开机启动mysql服务
添加开机启动:

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql

开机启动:

[root@localhost mysql]# chkconfig --add mysql
[root@localhost mysql]# chkconfig mysql on

启动mysql服务:

[root@localhost mysql]# service mysql start

5.修改mysql的root用户密码,root初始密码为空的

[root@localhost mysql]# ./bin/mysqladmin -u root password '123456'

6.把mysql客户端放到默认路径

[root@localhost mysql]# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

7.遇到问题

[root@localhost mysql]# cd bin/
[root@localhost bin]# ./mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方法:

[root@localhost bin]# service mysql stop
[root@localhost bin]# ./mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@localhost bin]# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
mysql> FLUSH PRIVILEGES;

8.配置防火墙

在防火墙配置文件中添加一行3306端口:

[root@localhost ~]# vim /etc/sysconfig/iptables

加入下面配置:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

重启防火墙:

[root@localhost ~]# service iptables restart

9.Mysql配置远程登录

配置所有IP可以访问:

[root@localhost ~]# mysql -u root -p123456
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

10.配置my.cnf

[root@localhost bin]# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
[root@localhost bin]# vim /etc/my.cnf

在[mysqld]下面加入:

character_set_server=utf8

11.重启mysql

[root@localhost bin]# service mysql restart

 

安装到此结束.

 

 

 

posted @ 2022-10-27 08:48  何童鞋  阅读(136)  评论(0编辑  收藏  举报