mysql安装之--redhat6.5安装解压版mysql

安装mySQL(我安装的是mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz)

先检查系统自带的mysql:

rpm –qa|grep –i mysql


#rpm -qa |grep -i mysql

mysql-libs-5.1.71-1.el6.x86_64


卸载掉:

rpm-e --nodeps mysql-libs-5.1.71-1.el6.x86_64

创建mysql用户和组

groupadd mysql

useradd -r -g mysql mysql

 

解压mysql到指定安装目录下,一般选择/usr/local/,这里选择/home/mysql:

#cd /home/mysql

#tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64

###更改授权给mysql用户和组

[root@localhost]#chown -R mysql:mysql mysql-5.7.22-linux-glibc2.12-x86_64


接下来配置mysql配置文件,内容如下(红字为必要添加的内容):

 [root@hl-gftest1etc]# vi /etc/my.cnf

# For advice on how to change settingsplease see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's atemplate which will be copied to the

# *** default location during install, andwill be replaced if you

# *** upgrade to a newer version of MySQL.

 

[mysqld]

 

# Remove leading # and set to the amount ofRAM for the most important data

# cache in MySQL. Start at 70% of total RAMfor dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

 

# Remove leading # to turn on a veryimportant data integrity option: logging

# changes to the binary log betweenbackups.

# log_bin

 

# These are commonly set, remove the # andset as required.

basedir=/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64

datadir=/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/data

max_allowed_packet=200M

# port = .....

# server_id = .....

# socket = .....

 

character_set_server =utf8

init_connect = 'SET NAMESutf8'

 

# Remove leading # to set options mainlyuseful for reporting servers.

# The server defaults are faster fortransactions and fast SELECTs.

# Adjust sizes as needed, experiment tofind the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

lower_case_table_names=1

[mysql]

default-character-set =utf8

[mysql.server]

default-character-set =utf8

[mysqld_safe]

default-character-set =utf8

[client]

default-character-set =utf8


将mysql配置文件配置到环境变量,添加到/etc/profile中

vim /etc/profile

在PATH中添加mysql的安装目录和bin目录:

/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64:/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/bin:

添加位置如下:



重启服务器或source /etc/profile使配置文件生效,添加mysql服务开机启动

cp -ar /home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/support-files/mysql.server  /etc/init.d/mysqld


接下来使用mysql用户初始化数据库

cd /home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64

mkdir data

bin/mysql_install_db --user=mysql --basedir=/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64 --datadir=/home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/data


启动mysql服务:

service mysqld start


修改root密码(如果mysqladmin修改root密码报错,请参考https://blog.csdn.net/u012206025/article/details/80927778):

cd /home/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/bin

mysqladmin -uroot password 'root@123'

登陆查看字符集:

mysql -uroot –p

然后输入密码回车进入数据库:


查看字符集设置是否正确:

show variables like '%character%';


开启远程连接:选择要使用的mysql数据库,修改远程连接的基本信息。

use mysql


更改远程连接设置:

GRANTALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root@123' WITH GRANTOPTION;

刷新刚才修改的权限,使其生效

flush privileges;

查看修改是否成功:

select host,user from user;


有红框里的东西就成功,退出重启mysql。

退出mysql:mysql>quit

service mysqld restart


Mysql至此安装完毕,安装mysql比较容易出错,我们只要根据mysql的data目录下生成的xxxx.err日志文件信息来调整就行了



你可能感兴趣的:(Mysql数据库安装)