centos安装mysql数据库(2018-09-28)

首先需要下载安装文件3个:

MySQL-client-5.6.37-1.el7.x86_64.rpm 

MySQL-devel-5.6.37-1.el7.x86_64.rpm 

MySQL-server-5.6.37-1.el7.x86_64.rpm

使用rpm安装

rpm -ivh ./MySQL-server-5.6.37-1.el7.x86_64.rpm

若需查询移除:

rpm -qa | grep -i MySQL

rpm -e MySQL-server-5.6.37-1.el7.x86_64.rpm

然后配置my.cnf到/etc下

my.cnf内容如下:



[mysqld]

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

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

innodb_buffer_pool_size = 64M

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

# changes to the binary log between backups.

# log_bin

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

# basedir = .....

# datadir = .....

# port = .....

# server_id = .....

# socket = .....

user=mysql

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

join_buffer_size = 64M

sort_buffer_size = 2M

read_rnd_buffer_size = 2M

key_buffer_size = 64M

performance_schema_max_table_instances=400

table_definition_cache=400

table_open_cache=256

[client]

socket=/var/lib/mysql/mysql.sock

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES



使用如下命令启动

/etc/init.d/mysql start

第一次启动会创建一个随机密码,位于

/root/.mysql_secret最后一行

修改登陆密码,登陆

mysql -u root -p

输入刚才的随机密码,进入mysql命令行

第一次登陆不能输入其它命令,需执行修改密码命令

SET PASSWORD=PASSWORD('123456');

然后修改远程登陆的用户名和密码

use mysql;

update user set password=PASSWORD("123456") where user='root';

FLUSH PRIVILEGES;

quit;

若远程登陆失败,可mysql执行如下,插入远程登陆用户名

use mysql;

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

FLUSH PRIVILEGES;

安装完成,

你可能感兴趣的:(centos安装mysql数据库(2018-09-28))