本文目錄一覽:
阿里雲服務器如何安裝MySQL數據庫
1.查看mysql編輯情況rpm -qa|grep mysql
2.卸載原有的mysql rpm -e –nodeps mysql
//
強力刪除模式,如果使用上面命令刪除時,提示有依賴的其它文件,則用該命令可以對其進行強力刪除
3.通過命令查看yum上面提供的可下載版本 yum list | grep mysql
4.安裝mysql客戶端和服務端 yum install -y mysql-server mysql mysql-deve
5.查看mysql啟動狀態 mysql service status
6.登錄mysql提示
7.修改mysql的root密碼
service mysqld stop
無密碼登錄mysql:mysqld_safe –skip-grant-tables
輸入mysql -uroot -p 直接回車進入mysql客戶端頁面
use mysql;
update user set password=PASSWORD(“root”)where user=”root”;修改密碼
flush privileges; 更新權限
service mysqld restart
最後直接登錄 mysql -u root -p回車輸入密碼
linux服務器上怎麼安裝mysql
安裝包:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
使用xshell連接linux服務器,使用root用戶名登錄,依次執行以下命令:
======================================================
/usr/sbin/groupadd mysql 【添加mysql組】
/usr/sbin/useradd -d /var/lib/mysql -s /sbin/nologin -g mysql mysql
mkdir -p /usr/local/src/mysql 【新建mysql文件夾】
cd / 【打開上傳安裝包的目錄】
mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz 【上傳安裝包到服務器的根目錄下】
mv mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz /usr/local/src/mysql【根目錄的安裝包移動到文件夾下】
cd /usr/local/src/mysql【打開目錄】
tar -zxvf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz【解壓安裝包】
cp mysql-5.6.30-linux-glibc2.5-x86_64 /usr/local/mysql -r【複製文件】
cd /usr/local【打開目錄】
chown -R mysql:mysql mysql/
cd /usr/local/mysql/scripts/【打開目錄】
./mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data【執行腳本】
cd /usr/local/mysql/support-files【打開目錄】
cp my-default.cnf /etc/my.cnf【複製文件到新的路徑下及文件名】
cp: overwrite `/etc/my.cnf’?Y【Y】
cp mysql.server /etc/init.d/mysql【複製文件到新的路徑下】
vim /etc/profile【編輯軟件運行環境】
vim i(編輯一些內容) esc(進入normal) w(保存文件) q(不保存退出文件)
###############################################################
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
###############################################################
source /etc/profile
chkconfig –add mysql
chkconfig mysql on
service mysql start
/usr/local/mysql/bin/mysqladmin -u root password ‘rootroot’【修改數據庫root的密碼】
grant all privileges on tdcdb.* to ‘root’@’%’ identified by ‘rootroot’ 【給mysql用戶分配權限】
flush privileges;
vim /etc/sysconfig/iptables【編輯訪問端口號】
###############################################################
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(添加3306的端口號)
###############################################################
service iptables restart
netstat -ntlp
mysql -u root -p (命令未找到使用: ln -s /usr/local/mysql/bin/mysql /usr/bin)
create user ‘tdc’@’%’ identified by ‘P@ssw0rd’;【創建數據庫訪問用戶】
create database if not exists `tdcdb`;【創建數據庫】
grant all privileges on tdcdb.* to ‘tdc’@’%’ identified by ‘P@ssw0rd’;【給tdc用戶分配訪問密碼】
flush privileges;
vi /etc/my.cnf【編輯配置文件,支持語言設置】
###############################
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8
###############################
service mysql stop【重新啟動mysql服務】
service mysql start
======================================================
linux 常用命令:
pwd:查看當前路徑
ll:2個小寫的L,查看當前目錄下的所有文件
cd:打開目錄,包括路徑地址及文件夾
vi 文件名:編輯linux下的文件,使用大寫的【I】命令來進行編輯,編輯完成後點擊【ESC】按鈕跳出編輯,輸入【:wq!】命令來退出保存;
注意:linux的文件不能打開直接修改,只能通過vi命令進行修改
======================================================
卸載程序的方式:
ps -ef | grep mysql
/etc/init.d/mysql status
whereis mysql
find / -name mysql【找到所有文件名為mysql的文件列表】
rm -rf /usr/local/mysql/【使用rm命令來移除列表中的文件】
rm -rf /etc/my.cnf【使用rm命令來移除列表中的文件】
如何在一台服務器上安裝兩個mysql或者更多
這種架構一般用在以下三類場景
1. 備份多台 Server 的數據到一台如果按照數據切分方向來講,那就是垂直切分。比如圖 2,業務 A、B、C、D 是之前拆分好的業務,現在需要把這些拆分好的業務匯總起來備份,那這種需求也很適用於多源複製架構。實現方法我大概描述下:業務 A、B、C、D 分別位於 4 台 Server,每台 Server 分別有一個數據庫來隔離前端的業務數據,那這樣,在從庫就能把四台業務的數據全部匯總起來,而不需要做額外的操作。那沒有多源複製之前,要實現這類需求,只能在匯總機器上搭建多個 MySQL 實例,那這樣勢必會涉及到跨庫關聯的問題,不但性能急劇下降,管理多個實例也沒有單台來的容易。
2. 用來聚合前端多個 Server 的分片數據。
同樣,按照數據切分方向來講,屬於水平切分。比如圖 3,按照年份拆分好的數據,要做一個匯總數據展現,那這種架構也非常合適。實現方法稍微複雜些:比如所有 Server 共享同一數據庫和表,一般為了開發極端透明,前端配置有分庫分表的中間件,比如愛可生的 DBLE。
3. 匯總併合並多個 Server 的數據
第三類和第一種場景類似。不一樣的是不僅僅是數據需要匯總到目標端,還得合併這些數據,這就比第一種來的相對複雜些。比如圖 4,那這樣的需求,是不是也適合多源複製呢?答案是 YES。那具體怎麼做呢?
怎麼安裝mysql服務端
1、首先,解壓下載的MySql安裝包。
2、雙擊打開解壓後的包,點擊如圖程序。
3、勾選協議,點擊next。
4、選擇安裝類型,點擊下一步。
5、設置安裝路徑。
6、點擊install。
7、點擊finsh。
8、點擊下一步。
9、選擇配置類型。
10、根據自己的需求選擇配置。
11、勾選第一個,點擊next。
12、設置並發量。
13、設置端口。
14、設置字符編碼。
15、設置服務器配置。
16、設置賬戶和密碼。
17、點擊excute。
18、點擊finsh,安裝完畢。
如何安裝MYSQL
使用yum安裝mysql數據庫的軟件包 [root@xuegod63 ~]# yum -y install mariadb-server mariadb 。
註: mariadb-server #MariaDB數據庫 mariadb # MariaDB服務器Linux下客戶端 。
註:從centos7系統開始,系統中自帶的mysql數據庫變成了mariadb-server,mariadb-server和mysql操作上一樣。mariadb-server是mysql的一個分支。
啟動數據庫服務[root@xuegod63 ~]# systemctl start mariadb #啟動MariaDB服務。[root@xuegod63 ~]# systemctl enable mariadb #設置開啟自動啟動MariaDB服務。
安裝完mariadb-server後,運行mysql_secure_installation去除安全隱患,[root@xuegod63 ~]# mysql_secure_installation #進入安全配置導向。
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQLSERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current,password for the root user. If you’ve just installed MySQL, 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): #初次運行直接回車,因為root用戶沒有密碼。
OK, successfully used password, moving on,Setting the root password ensures that nobody can log into the MySQL,root user without the proper authorisation.,Set root password? [Y/n] Y #是否設置root用戶密碼,輸入Y。
New password: 123456 #新密碼123456,Re-enter new password: 123456,Password updated successfully!Remove anonymous users? [Y/n] Y #是否刪除匿名用戶,生產環境建議刪除,所以直接回車或Y。
Success!Normally, root should only be allowed to connect from ‘localhost’. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] Y #是否禁止root遠程登錄,根據自己的需求選擇Y/n並回車建議禁止。
Success!By default, MariaDB comes with a database named ‘test’ that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] Y #是否刪除test數據庫,直接回車或Y。
原創文章,作者:XKMP,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/140545.html