centos下安装mysql

目录

一.环境准备

1. 查找mariadb

2. 删除mariadb

二.安装mysql

1.解压mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

2. 修改配置文件

3.创建用户以及授权

4 .安装mysql

三.配置mysql

1.设置权限

2 .设置PATH路径

四.mysql 基本使用及设置

1.登录mysql

2.修改root密码


一.环境准备

1. 查找mariadb

[root@achao ~]# rpm -qa|grep mariadb

mariadb-libs-5.5.56-2.el7.x86_64

2. 删除mariadb

[root@achao ~]# rpm -e --nodeps  mariadb-libs-5.5.56-2.el7.x86_64

二.安装mysql

1.解压mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

[root@achao ~]# tar -xzvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

[root@achao ~]# mv mysql-5.5.62-linux-glibc2.12-x86_64    mysql-5.5.62

[root@achao ~]# mv mysql-5.5.62  /usr/local/mysql

2. 修改配置文件

[root@achao ~]# vi /etc/my.cnf    

[mysql]

default-character-set=utf8    

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

[mysqld]

skip-name-resolve

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

basedir=/usr/local/mysql  

datadir=/usr/local/mysq/data  

max_connections=200

character-set-server=utf8

lower_case_table_name=1

max_allowed_packet=16M

~

"/etc/my.cnf" [New] 27L, 754C written

3.创建用户以及授权

[root@achao mysql]# groupadd mysql

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

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

4 .安装mysql

[root@achao ~]# cd /usr/local/mysql/

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

Installing MySQL system tables...

230227 11:32:57 [Warning] Using unique option prefix lower_case_table_name instead of lower_case_table_names is deprecated and will be removed in a future release. Please use the full name instead.

230227 11:32:57 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

230227 11:32:57 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.5.62) starting as process 1574 ...

OK

Filling help tables...

230227 11:32:57 [Warning] Using unique option prefix lower_case_table_name instead of lower_case_table_names is deprecated and will be removed in a future release. Please use the full name instead.

230227 11:32:57 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

230227 11:32:57 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.5.62) starting as process 1581 ...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/local/mysql//bin/mysqladmin -u root password 'new-password'

/usr/local/mysql//bin/mysqladmin -u root -h 192.168.20.135 password 'new-password'

Alternatively you can run:

/usr/local/mysql//bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl

Please report any problems at MySQL Bugs    #看到此次就表示安装成功

 

三.配置mysql

1.设置权限

[root@achao mysql]# ls

bin      data  include         lib  mysql-test  scripts  sql-bench

COPYING  docs  INSTALL-BINARY  man  README      share    support-files

[root@achao mysql]# chown -R mysql:mysql data

[root@achao mysql]# chmod 777 /etc/my.cnf

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

[root@achao mysql]# chmod +x /etc/init.d/mysqld

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

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

[root@achao mysql]# mkdir /var/lib/mysql

[root@achao mysql]# chmod 777 /var/lib/mysql

[root@achao mysql]# service mysqld start   #开启服务

Warning: World-writable config file '/etc/my.cnf' is ignored

Starting MySQL.Warning: World-writable config file '/etc/my.cnf' is ignored

Warning: World-writable config file '/etc/my.cnf' is ignored

Logging to '/usr/local/mysql/data/achao.err'.

. SUCCESS!      #成功

[root@achao mysql]# ss -alnpt   #查看端口

State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              

LISTEN     0      50             *:3306                      *:*                   users:(("mysqld",pid=1717,fd=10))

LISTEN     0      128            *:22                         *:*                   users:(("sshd",pid=983,fd=3))

LISTEN     0      100    127.0.0.1:25                         *:*                   users:(("master",pid=1210,fd=13))

LISTEN     0      128           :::22                        :::*                   users:(("sshd",pid=983,fd=4))

LISTEN     0      100          ::1:25                        :::*                   users:(("master",pid=1210,fd=14))

 #看到3306端口,说明启动成功。

2 .设置PATH路径

[root@achao mysql]# vi ~/.bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH=$PATH:/usr/local/mysql/bin     #注意看这里

[root@achao mysql]# source ~/.bash_profile   #刷新

四.mysql 基本使用及设置

1.登录mysql

[root@achao mysql]# mysql -u root -p

默认是没有密码的,直接回车。 

2.修改root密码

mysql> use mysql;  #使用mysql数据库

mysql> update user set password=password('123456')  where user='root' and host='localhost';   #更新密码为123456,当用户是root和主机是本地主机。

mysql> flush privileges;   #刷新权限

mysql> exit   #退出

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值