1. 程式人生 > >CentOS7用yum安裝 MySQL

CentOS7用yum安裝 MySQL

usr show secure mes named ucc source ror postfix

首先CentOS7 已經不支持mysql,因為收費了你懂得,所以內部集成了mariadb,而安裝mysql的話會和mariadb的文件沖突,所以需要先卸載掉mariadb,以下為卸載mariadb,安裝mysql的步驟。

#列出所有被安裝的rpm package
rpm -qa | grep mariadb

#卸載
rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64
錯誤:依賴檢測失敗:
libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要

#強制卸載,因為沒有--nodeps
rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64

#安裝mysql依賴
yum install vim libaio net-tools

其他情況:

1、centos下yum暫時沒有mysql-server直接安裝包;
MariaDB是MySQL社區開發的分支,也是一個增強型的替代品;

2、安裝MariaDB
yum -y install mariadb-server mariadb mariadb-devel
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
firewall-cmd --permanent --add-service mysql
systemctl restart firewalld.service
iptables -L -n|grep 3306

In order to log into MariaDB to secure it, we‘ll need the current
password for the root user.  If you‘ve just installed MariaDB, and
you haven‘t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

此處可以設置mysql的密碼

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from ‘localhost‘.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named ‘test‘ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you‘ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

跟著上面的設置,註意remote login這裏設置為n.

1. 下載mysql的repo源

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. 安裝mysql-community-release-el7-5.noarch.rpm包

$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

安裝這個包後,會獲得兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。

3. 安裝mysql

$ sudo yum install mysql-server

根據步驟安裝就可以了。

[root@nicknailo ~]# /usr/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11

輸入上面的設置密碼

進入mysql客戶端之後,show databases;

啟動mysql服務:

1、使用 service 啟動:service mysqld start
2、使用 mysqld 腳本啟動:/etc/inint.d/mysqld start

持久化啟動mysql cd /usr/bin/,

pm2 start mysql

[PM2] Starting /usr/bin/mysql in fork_mode (1 instance)

[PM2] Done.

┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐

App name id mode pid status restart uptime cpu mem user watching

├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤

app 1 fork 2330 online 0 95m 0% 37.3 MB root disabled

app 3 fork 3498 online 0 82m 0% 25.2 MB root disabled

mongo 0 fork 2104 online 0 104m 0% 11.5 MB root disabled

mysql 5 fork 11449 online 0 0s 0% 2.0 MB root disabled

└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘

Use `pm2 show <id|name>` to get more details about an app

CentOS7用yum安裝 MySQL