Ubuntu 管理心得

搜尋此網誌

針對查詢「mysql」依關聯性排序顯示文章。依日期排序 顯示所有文章
針對查詢「mysql」依關聯性排序顯示文章。依日期排序 顯示所有文章

2022年2月12日 星期六

Install LAMP server

 cf: https://upcloud.com/community/tutorials/installing-lamp-stack-ubuntu/

 

  1. sudo apt update
  2. sudo apt install apache 
  3. sudo systemctl status apache2
  4. sudo apt install php7.4 php7.4-mysql php-common php7.4-cli php7.4-json php7.4-common php7.4-opcache libapache2-mod-php7.4
  5. sudo systemctl restart apache2
  6. sudo apt install mariadb-server mariadb-client
  7. sudo systemctl status mariadb
  8. sudo mysql_secure_installation
    As you have no root password set for MariaDB you should simply press Enter when prompted, pressing Y on the next question to then set a root password (keep this safe and secure!) With that set, you can press Enter for the remaining questions as the defaults for each of these will help to secure your new installation.
  9. mysql_secure_installation

    https://mariadb.com/kb/en/mysql_secure_installation/
  10. Run mysql_secure_installation
  11. cf: https://kpchiaoo.blogspot.com/search?q=mysql
    If can't access mysql as mysql user root from normal user account but can access mysql without mysql root password from ubuntu root accout, then follow the lines below (the parentheses are comments):
    cf: https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04/801950
        (1). su - (get into ubuntu root account)
        (2). mysql -u root (get into mysql, should be no need password)
        (3). select User,host,plugin from mysql.user;
        (4). update mysql.user set plugin = 'mysql_native_password' where User='root';
        (5). select User,host,plugin from mysql.user; (plugin column should be changed)
        (6). SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new password');
    or for mysql 8.0 in ubuntu 20.04
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassord' 
        (7). flush privileges;
  12. sudo a2enmod userdir
  13. sudo a2enmod rewrite
  14. sudo vim php7.4.conf Commnent out the following lines:
    #<IfModule mod_userdir.c>
    #    <Directory /home/*/public_html>
    #        php_admin_flag engine Off
    #    </Directory>
    #</IfModule>
     
  15. sudo apt install phpmyadmin
  16. cf: https://stackoverflow.com/questions/42490647/phpmyadmin-installation-error-1045-acces-denied-using-password-no
    $ mysql -u root -p
    mysql> create database phpmyadmin;
    mysql> create user 'phpmyadmin'@'localhost' identified by 'some_passwd';

    mysql> grant all privileges on phpmyadmin.* to 'phpmyadmin'@'localhost'
  17. cd  /usr/share/phpmyadmin/sql
    $ mysql -u phpmyadmin -p phpmyadmin < create_tables.sql
  18. Edit /etc/php/7.4/apache2/php.ini
    post_max_size = 200M
    upload_max_filesize = 200M
  19. Edit /etc/apache2/apache2.conf, add the lines:
    <Directory /home/chiao/public_html/drupal9/web>
    Options FollowSymLinks
    AllowOverride AuthConfig FileInfo Indexes Limit Options=All,MultiViews
    </Directory>
  20. sudo systemctl restart apache2

 

2018年7月17日 星期二

My Ubuntu post-installation

1. sudo apt install aptitude qttools5-dev libqscintilla2-qt5-dev f2c gfortran libblas-dev liblapack-dev libpcre3-dev libreadline-dev net-tools openssh-server krusader gnome-tweaks oxygen-icon-theme xul-ext-lightning kate tasksel dvipng texlive-latex-extra texlive-fonts-recommended libcanberra-gtk-module kde-cli-tools keditbookmarks guake synaptic kio-extras okular latex-cjk-chinese texlive-lang-cjk samba nfs-common nfs-kernel-server gparted lftp texlive texlive-extra-utils texlive-font-utils texlive-fonts-extra lynx jupyter python3-numpy python3-matplotlib python3-scipy texlive-publishers classicmenu-indicator texlive-fonts-extra deborphan texlive-science kbibtex xfig ethool htop gimp gimp-plugin-registry gimp-data
2. 在「 軟體與更新」中,設定源碼
3. sudo apt-get build-dep lyx
4. sudo apt purge lyx lyx-common
5. cd /download1/LyX/lyx-2.3.0
    ./configure --enable-qt5
    make
    sudo make install
6. sudo apt-get build-dep octave

    cd /download1/Octave/octave-7.1.0

    ./configure --with-qt=5 (may not need --with-qt=5)
    make
    make install
6. wget http://download.nomachine.com/download/6.2/Linux/nomachine_6.2.4_1_amd64.deb
    sudo dpkg -i nomachine_6.2.4_1_amd64.deb
6. tasksel-> LAMP server
7. If can't access mysql as mysql user root from normal user account but can access mysql without mysql root password from ubuntu root accout, then follow the lines below (the parentheses are comments):
cf: https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04/801950
    (1). su - (get into ubuntu root account)
    (2). mysql -u root (get into mysql, should be no need password)
    (3). select User,host,plugin from mysql.user;
    (4). update mysql.user set plugin = 'mysql_native_password' where User='root';
    (5). select User,host,plugin from mysql.user; (plugin column should be changed)
    (6). SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new password');
or for mysql 8.0 in ubuntu 20.04
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassord' 
    (7). flush privileges;

8. guake hangs when exit press Ctrl-D.
sudo apt install libutempter0
Solve the hanging problem (cf:https://github.com/Guake/guake/issues/1198)

9. add new user for samba:
sudo smbpasswd -a chiao
then input password (twice)

2021年11月27日 星期六

Cannpt login as mysql user root from normal user account

 cf: https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04


$ sudo mysql -u root
mysql> DROP USER 'root'@'localhost';
mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY '<root_password>';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION; 
mysql> FLUSH PRIVILEGES;
 
In above, One replace 'root' e.g. with 'chiao' to create the a mysql user as root.  

2020年2月9日 星期日

mysql installation on ubuntu 18.04

  1. sudo apt update
  2. sudo apt install mysql-server
  3. sudo mysql_secure_installation
  4. sudo mysql, then issue the command: SELECT user,authentication_string,plugin,host FROM mysql.user;
Originally, the root user is authenticated with the "auth_socket" plugin.
To configure the root account to authenticate with a password,
run the following ALTER USER command.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
 
Replacing the 'password' with a new strong password. 
Note that this command will change the root password you set in Step 2. 

2019年12月28日 星期六

Using root login mysql with password

sudo mysql
ALTER USER 'root'@'localhost%' IDENTIFIED WITH mysql_native_password BY 'your-password';
FLUSH PRIVILEGES;
exit;
 

2023年5月6日 星期六

Create class databases and users for dam

Create the following sql file, say, createdam.sql, then run
mysql -u chiao -o mysql < createdam.sql

      --  createdam.sql, ------------------------------------------------------

DROP PROCEDURE IF EXISTS createUserDatabases;
DELIMITER //

CREATE PROCEDURE createUserDatabases()
BEGIN
  -- Create the users and their databases, and grant privileges
  SET @users = 'Team112, Monkey, WhileTrue, clear, DIEGO';
  SET @passwords = 'AA090078, AA090107, AA091227, AA091233, AA091223';
  SET @privileges = 'SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER';

  SET @delimiter = ', ';
  SET @count = 1;
  SET @total_users = LENGTH(@users) - LENGTH(REPLACE(@users, @delimiter, '')) + 1;

  WHILE @count <= @total_users DO
    SET @current_user = SUBSTRING_INDEX(SUBSTRING_INDEX(@users, @delimiter, @count), @delimiter, -1);
    SET @current_password = SUBSTRING_INDEX(SUBSTRING_INDEX(@passwords, @delimiter, @count), @delimiter, -1);
    SET @current_database = CONCAT('dam1112_', @current_user);
    SET @current_privileges = SUBSTRING_INDEX(SUBSTRING_INDEX(@privileges, @delimiter, @count), @delimiter, -1);

    -- Create the user and set the password
    SET @create_user_sql = CONCAT('CREATE USER IF NOT EXISTS \'', @current_user, '\' IDENTIFIED BY \'', @current_password, '\'');
    PREPARE createUserStmt FROM @create_user_sql;
    EXECUTE createUserStmt;
    DEALLOCATE PREPARE createUserStmt;

    -- Create the database and grant privileges
    SET @create_db_sql = CONCAT('CREATE DATABASE IF NOT EXISTS \`', @current_database, '\`');
    PREPARE createDbStmt FROM @create_db_sql;
    EXECUTE createDbStmt;
    DEALLOCATE PREPARE createDbStmt;

    SET @grant_privileges_sql = CONCAT('GRANT ', @current_privileges, ' ON \`', @current_database, '\`.* TO \'', @current_user, '\'');
    PREPARE grantPrivilegesStmt FROM @grant_privileges_sql;
    EXECUTE grantPrivilegesStmt;
    DEALLOCATE PREPARE grantPrivilegesStmt;

    SET @delete_fuzzyahp_sql = CONCAT('DELETE FROM \`fuzzyahp\`.\`fahpdatabase\` WHERE \`fahpdatabase\`.\`user\` = \'',  @current_user, '\' AND \`fahpdatabase\`.\`database\` = \'', @current_database, '\'');
    PREPARE deleteStmt FROM @delete_fuzzyahp_sql;
    EXECUTE deleteStmt;
    DEALLOCATE PREPARE deleteStmt;

    SET @insert_fuzzyahp_sql = CONCAT('INSERT INTO \`fuzzyahp\`.\`fahpdatabase\` (\`user\`, \`database\`) VALUES (\'', @current_user, '\', \'', @current_database, '\')');
    PREPARE insertStmt FROM @insert_fuzzyahp_sql;
    EXECUTE insertStmt;
    DEALLOCATE PREPARE insertStmt;

    SET @count = @count + 1;
  END WHILE;
END //

DELIMITER ;

CALL createUserDatabases();

--  createdam.sql, ------------------------------------------------------

2024年9月13日 星期五

unzip sql into mysql

gunzip -cv drupal10_from_9_20240914.sql.zip | mysql -v -u chiao -p drupal10_from_9

2020年1月2日 星期四

clone grade database

Clone from  kpci7:
mysqldump -u chiao -h localhost  -p grade_108_1 > grade_108_1_20200103.sql

to kpchiaoi5:
mysql -u chiao -p grade_108_1 < grade_108_1_20200103.sql



2021年11月7日 星期日

Clone drupal9 to pi4

  1. The source directory chiao@pi4:~/public_html/drupal9 does not need to be changed.
  2. Export drupal database from kpci7 as sql source file from here.
  3. Save the sql as drupal_kpci72004_20211108.sql
  4. sed 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g' drupal_kpci72004_20211108.sql > drupal_kpci72004_20211108_update.sql
  5. Import drupal_kpci72004_20211108_update.sql to pi4 MySQL database (by phpmyadmin):
    1. Clone drupal database in pi4 as drupal_pi4_20211108
    2. Drop drupal database in pi4
    3. Import drupal_kpci72004_20211108_update.sql
  6.  Done.

2024年4月2日 星期二

Clone 教學網頁

  1. Rename drupal0_from_9 database to drupal10_from_9_pi4_20240402
  2. Using command line mysql instead of phpmyadmin to clone draupal0_from_9 database from kpci7 to pi4
  3. Using sudo to clone public_html/drupal10_from_9 from kpci7 to pi4
  4. In pi4 phpmyadmin, update the drupal10_from_9 database privileges for drupaladmin

2019年3月25日 星期一

Copy drupal from kpchiaoi5 to kpci7

In kpchiai5:
  1. mysqldump -u drupaladmin -h localhost --skip-lock-tables -p drupal > drupal_20160826_kpchiaoi5.sql
  2. gzip -9 drupal_20160826_kpchiaoi5.sql
  3. sudo tar zcvf public_html_drupal_20160826_kpchiaoi5.tgz public_html/drupal

In kpci5:
  1. download from kpchiaoi5: drupal_20160826_kpchiaoi5.sql.gz, public_html_drupal_20160826_kpchiaoi5.tgz
  2. gzip -dc drupal_20160826_kpchiaoi5.sql.gz | sed -e '/^UNLOCK/d' -e '/^LOCK/d' > ~/a.sql
  3. Using phpmyadmin to drop all drupal tables.
  4. mysql -u drupaladmin -p drupal < ~/a.sql
  5. sudo tar zxvfp public_html_drupal_20160826_kpchiaoi5.tgz -C /home/chiao
  6. sudo chown -R www-data.www-data /home/chiao/public_html/drupal (IMPORTANT!!!!)
  7. 6. 設定 -> 開發 -> 效能 -> 清除所有快取

2023年3月18日 星期六

php stuff in pi4

  1. sudo apt purge php*
  2. sudo apt install php8.0
  3. sudo apt install php8.0-mysql
    sudo apt install php8.0-dom
    sudo apt install php8.0-mbstring
    sudo apt install php8.0-fpm
    sudo apt install php8.0-pear
    sudo apt install php-pear

Install phpmyadmin on pi raspbian bullseye

 cf: http://linux.how2shout.com/how-to-install-phpmyadmin-on-debian-11-bullseye-apache/

  1. sudo apt -y install php-cgi php-mysqli php-pear php-mbstring libapache2-mod-php php-common php-phpseclib php-mysql
  2. wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
  3. sudo tar xvf phpMyAdmin-latest-all-languages.tar.gz
  4. sudo mv phpMyAdmin-*-all-languages/ /var/www/html/phpmyadmin
  5. cd /var/www/html
    sudo cp phpmyadmin/config.sample.inc.php phpmyadmin/config.inc.php
  6. sudo mkdir /var/www/html/phpmyadmin/tmp
  7. openssl rand -base64 32
    (copy the output key)
  8. sudo vim /var/www/html/phpmyadmin/config.inc.php
  9. Put the key in Step 6 into:
    $cfg[‘blowfish_secret’] = ‘your-key‘; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
  10. And add this line:
    $cfg['TempDir'] = '/var/www/html/phpmyadmin/tmp';
  11. sudo chown -R www-data:www-data /var/www/html/phpmyadmin
  12. sudo vim /etc/apache2/conf-available/phpmyadmin.conf
  13. Add the followings:
    Alias /phpmyadmin /var/www/html/phpmyadmin

    <Directory /var/www/html/phpmyadmin/>
       AddDefaultCharset UTF-8
       <IfModule mod_authz_core.c>
              <RequireAny>
          Require all granted
         </RequireAny>
       </IfModule>
    </Directory>

    <Directory /var/www/html/phpmyadmin/setup/>
       <IfModule mod_authz_core.c>
         <RequireAny>
           Require all granted
         </RequireAny>
       </IfModule>
    </Directory>
  14. sudo a2enconf phpmyadmin.conf
  15. sudo systemctl restart apache2

網誌存檔