Linux yum 安裝Java和MySQL


1、Linux配置Java環境

CentOS系統默認是帶有yum(軟件包依賴管理工具)的,Ubuntu是apt,macOS是homebrew

yum -y update 升級所有包同時也升級軟件和系統內核

yum -y upgrade 只升級所有包,不升級軟件和系統內核

 

安裝之前先檢查一下系統有沒有自帶open-jdk

rpm -qa |grep java

rpm -qa |grep jdk

rpm -qa |grep gcj

如果沒有輸入信息表示沒有安裝。

如果安裝可以使用 rpm -qa | grep java | xargs rpm -e --nodeps 批量卸載所有帶有Java的文件  這句命令的關鍵字是java

yum list java*  檢索包含java的列表

yum install java-1.8.0-openjdk* -y  安裝1.8.0的所有文件


java -version  檢查是否安裝成功(yum安裝都不用配置環境變量)

 

2、Linux配置MySQL

yum安裝MySQL,主要是3個包

mysql-devel 開發用到的庫以及包含文件
mysql mysql 客戶端
mysql-server 數據庫服務器

 

安裝之前,先說收如何徹底卸載MySQL

用命令rpm -qa|grep -i mysql查看已經安裝的MySQL安裝包,在列表中逐個卸載

yum remove mysql mysql-server mysql-libs compat-mysql51 

rm -rf /var/lib/mysql  

rm /etc/my.cnf

 

查看以前是否安裝過

yum list installed mysql*

rpm -qa | grep mysql*

 

安裝MySQL

yum install mysql

yum install mysql-server

yum install mysql-devel

 

配置MySQL

[root@wood /]# cat /etc/my.cnf

[client]

default-character-set=utf8

 

[mysql]

default-character-set = utf8

 

[mysqld]

character_set_server=utf8

character_set_client=utf8

collation-server=utf8_general_ci

max_connections=100

datadir=/var/lib/mysql

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

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

[mysqld_safe]

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

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

 

 

開機啟動 MySQL

chkconfig -add mysqld

 

 

啟動、停止 MySQL

service mysqld start

service mysqld stop

service mysqld restart

 

第一次啟動會彈出

[root@wood ~]# service mysqld start

Initializing MySQL database:  Installing MySQL system tables...

OK

Filling help tables...

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/bin/mysqladmin -u root password 'new-password'

/usr/bin/mysqladmin -u root -h wood password 'new-password'

 

Alternatively you can run:

/usr/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 ; /usr/bin/mysqld_safe &

 

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

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

 

Please report any problems with the /usr/bin/mysqlbug script!

 

設置管理員密碼

設置mysql管理員密碼

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

/usr/bin/mysqladmin -u root -h localhost password 'new-password'

配置mysql安裝向導

/usr/bin/mysql_secure_installation

 

修改localhost,任何IP都可以遠程訪問mysql服務器
更改 "mysql" 數據庫里的 "user" 表里的 "host" 項,從"localhost"改成"%" 
mysql>use mysql; 
mysql>update user set host = '%' where user = 'root'; 
mysql>select host, user from user;
mysql>FLUSH PRIVILEGES;

 

為了安全,我是這樣設置的

話說IP怎么查?

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM