ubuntu下安装mysql

http://www.mysql.com/downloads/mysql
sudo groupadd mysql
sudo useradd -r -g mysql mysql
sudo passwd mysql
sudo tar zxvf ~/Downloads/mysql-5.5.29-linux2.6-x86_64.tar.gz -C /opt
sudo mv /opt/mysql-5.5.29-linux2.6-x86_64 /opt/mysql
sudo chown -R mysql:mysql /opt/mysql
sudo apt-get install libaio1
sudo apt-get -f install
cd /opt/mysql
sudo scripts/mysql_install_db --user=mysql --basedir=. --datadir=./data
sudo cp support-files/mysql.server /etc/init.d/mysql.server
sudo cp support-files/my-medium.cnf /etc/my.cnf
sudo mkdir /var/run/mysqld
sudo mkdir /var/log/mysql
sudo chown mysql:mysql /var/run/mysqld
sudo chown mysql:mysql /var/log/mysql
sudo gedit /etc/init.d/mysql.server
basedir="/opt/mysql"
sudo gedit /etc/my.cnf
在[client]下添加
default-character-set=utf8
在[mysqld]下添加
character-set-server=utf8(mysql5.5之前版本添加default-character-set=utf8)
sudo service mysql.server start # [start|stop|status]
或者
sudo /etc/init.d/mysql.server start # [start|stop|status]
sudo /opt/mysql/bin/mysqladmin -u root password root
sudo update-rc.d mysql.server defaults
# 取消开机启动
# sudo update-rc.d -f mysql.server remove

以下是mysql日常操作:

sudo rm -rf /etc/mysql
mysql -uroot -p
use mysql;
select host, user from user;
grant all privileges on *.* to root@'%' identified by "mypassword" WITH GRANT OPTION;
FLUSH PRIVILEGES;
mysql -uroot -p
use mysql;
select host, user from user;
revoke all privileges on *.* from root@'%';
delete from user where user='root' and host='%';
FLUSH PRIVILEGES;

相关推荐