MySQL在linux上的二进制安装方法

时间:2022-09-13 21:06:32

建组、建用户:

[root@dbking mysql]# groupadd mysql

[root@dbking mysql]# useradd -g mysql mysql

解压安装程序:

[root@dbking mysql]# tar -zxvf mysql.tar.gz

[root@dbking mysql]# mv /rpm/mysql /usr/local/mysql

初始化:

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

配置文件:

[root@dbking mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

port = 3306

log_error=mysql.err

修改目录权限:

[root@dbking mysql]# chown -R mysql:mysql /usr/local/mysql/

修改环境变量:

export PATH=/usr/local/mysql/bin:$PATH

启动数据库:

[mysql@dbking ~]$ /usr/local/mysql/bin/mysqld --user=mysql &

或者

[mysql@dbking ~]$ /usr/local/mysql/bin/mysqld_safe --user=mysql &

设置mysql开机自动启动:

[root@dbking mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

[root@dbking mysql]# chown -R root:root /etc/rc.d/init.d/mysqld

[root@dbking mysql]# chmod 755 /etc/rc.d/init.d/mysqld

[root@dbking mysql]# chkconfig --add mysqld

[root@dbking mysql]# chkconfig --list mysqld

mysqld          0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@dbking mysql]# service mysqld status

ERROR! MySQL is not running

mysql的root用户授权:

mysql> grant all privileges on *.* to 'root'@'%' identified by 'oracle';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> set password for 'root'@'%'=password('oracle');

Query OK, 0 rows affected (0.00 sec)